The SQL EXISTS command verifies if any records exist in a subquery, returning true if the subquery yields one or more records. In the example SQL below, it lists suppliers with a product price below 20.
SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId = Suppliers.supplierId AND Price < 20); |
The SQL below retrieves suppliers where the product price equals 22.
SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE SupplierId = Suppliers.supplierId AND Price = 22); |