Collections:
EXISTS - Testing Subquery Results in SQL Server
How To Test Subquery Results with the EXISTS Operator in SQL Server Transact-SQL?
✍: FYIcenter.com
EXISTS is a special operator used to test subquery results. EXISTS can be used in two ways:
EXISTS (SELECT ...) -- Returns TRUE if the specified subquery has one or more rows returned. NOT EXISTS (SELECT ...) -- Returns TRUE if the specified subquery no rows returned.
The following tutorial exercise shows you two examples of EXISTS operators. The sample database AdventureWorksLT provided by Microsoft is used.
USE AdventureWorksLT GO -- Number of customers with orders SELECT COUNT(*) FROM SalesLT.Customer c WHERE EXISTS ( SELECT * FROM SalesLT.SalesOrderHeader s WHERE s.CustomerID = c.CustomerID ) GO 32 -- Number of customers without orders SELECT COUNT(*) FROM SalesLT.Customer c WHERE NOT EXISTS ( SELECT * FROM SalesLT.SalesOrderHeader s WHERE s.CustomerID = c.CustomerID ) 408
⇒ IN - Testing Values Returned by a Subquery in SQL Server
⇐ Using Wildcard Characters in LIKE Operations in SQL Server
⇑ Boolean Values and Logical Operations in SQL Server Transact-SQL
2017-01-21, 2769🔥, 0💬
Popular Posts:
How To Count Rows with the COUNT(*) Function in SQL Server? If you want to count the number of rows,...
What Is a Parameter File in Oracle? A parameter file is a file that contains a list of initializatio...
What is test testing area for? The testing area is provided to allow visitors to post testing commen...
How To Recover a Dropped Index in Oracle? If you have the recycle bin feature turned on, dropped ind...
How To Connect to a MySQL Server with a Port Number in MySQL? If you want to connect a MySQL server ...