SQLite EXISTS Operator
The EXISTS Operator
EXISTS tests if a subquery returns any records. It is true if the subquery returns one or more records.
This example lists the suppliers that have a product with a price less than 20:
Example
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (
SELECT ProductName FROM Products
WHERE Products.SupplierID = Suppliers.SupplierID
AND Price < 20
);
Try it Yourself »
NOT EXISTS
NOT EXISTS is true when the subquery returns no records. This example lists the customers that have never placed an order:
Example
SELECT CustomerName
FROM Customers
WHERE NOT EXISTS (
SELECT * FROM Orders
WHERE Orders.CustomerID = Customers.CustomerID
);
Try it Yourself »