How to use Exists function on the SQL query?
The SQL EXISTS operator is a boolean operator used in SQL to check whether a subquery returns any rows. It returns TRUE if the subquery finds one or more rows and FALSE if no rows are found. EXISTS is commonly used in WHERE clauses to filter results based on the presence of rows in related tables.
--Syntax--
SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);
--Example--
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);