EXISTS in SQL

HOW TO USE EXISTS OPERATOR IN SQL?

EXISTS  is a boolean operator which returns TRUE if the subquery returns single or multiple records else it gives a false result when no records are returned. The EXISTS operator when detects the first true event, it automatically terminates for further processing. 

Syntax of EXISTS operator in SQL-

SELECT <column_name(s)> FROM <table_name>

WHERE EXISTS

(SELECT <column_name(s)> FROM <table_name> WHERE <condition>);

Example of EXISTS operator in SQL-

SELECT SupplierName

FROM Suppliers

WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID=Suppliers.supplierID AND Price>10); 

โ€“This SQL statement will lists the suppliers with a product price >10.


Posted

in

Tags:

Comments

Leave a Reply