The SQL EXISTS Operator
The EXISTS operator is used to test for the existence of any record in a subquery.
The EXISTS operator returns TRUE if the subquery returns one or more records.
Syntax
SELECT column_name(s) FROM table_name WHERE EXISTS ( SELECT column_name FROM table_name WHERE condition);
Demo Products table
This product table is used in examples:
Demo Supplier table
This supplier table is used for examples:
SQL EXISTS Example
The following SQL statement returns TRUE and lists the suppliers with a product price less than 1000:
Example
SELECT Supplier_name FROM supplier WHERE EXISTS ( SELECT Product_name FROM products WHERE products.Supplier_id = supplier.Supplier_id AND Price < 1000);You can click on above box to edit the code and run again.
Output
The following SQL statement returns TRUE and lists the suppliers with a product price equal to 1100: