EXISTS Operator

Determines if a given list of values contains at least one value.

 

Syntax

 

EXISTS list

 

The EXISTS operator has these parts:

 

Part

Description

list

A list of values or a query.

 

Remarks

 

Use the EXISTS operator to check if a list of values is empty or not. The EXISTS operator is typically used with a query, but we could use it with a list of values, in which case the operator will always return True.

 

Examples

 

This example uses the EXISTS operator to show whether each particular employee has served at least one order in July (any year):

 

SELECT [First Name], [Last Name], EXISTS (SELECT * FROM [Orders] WHERE [Orders].[Employee ID] = [Employees].[Employee ID] AND Month([Order Date]) = 7) FROM [Employees];

 

This example uses the EXISTS operator to select only those products that have a supplier in London (this can also be done with the INNER JOIN operator):

 

SELECT * FROM [Products] WHERE EXISTS (SELECT * FROM [Suppliers] WHERE [Suppliers].[Supplier ID] = [Products].[Supplier ID] AND [City] = "London");