SQL WHERE EXISTS Statement

  • WHERE EXISTS tests for the existence of any records in a subquery.
  • EXISTS returns true if the subquery returns one or more records.
  • EXISTS is commonly used with correlated subqueries.
The definitive guide
for data professionals


Order today!
 See 2 min video



The SQL EXISTS syntax


The general syntax is:
SELECT column-names
  FROM table-name
 WHERE EXISTS 
      (SELECT column-name
         FROM table-name
        WHERE condition)




SQL EXISTS Example



Problem: Find suppliers with products over $100.

SELECT CompanyName
  FROM Supplier
 WHERE EXISTS
       (SELECT ProductName
          FROM Product
         WHERE SupplierId = Supplier.Id 
           AND UnitPrice > 100)	

This is a correlated subquery because the subquery references the enclosing query (with Supplier.Id).

Results: 2 records

CompanyName
Plutzer Lebensmittelgroßmärkte AG
Aux joyeux ecclésiastiques