EXISTS operator
Syntax: returns TRUE/FALSE and then lists the values in the column that satisfies the condition in WHERE
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);
allow you to perform a comparison b/w a single column value & a range of other values
ANY Operator
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name operator ANY
(SELECT column_name
FROM table_name
WHERE condition);
Example: lists the ProductName if it finds ANY records in the OrderDetails table that has Quantity equal to 10
SELECT ProductName
FROM Products
WHERE ProductID = ANY
(SELECT ProductID
FROM OrderDetails
WHERE Quantity = 10);
ALL Operator
SELECT ALL column_name(s)
FROM table_name
WHERE condition;
ALL Syntax with WHERE or HAVING
SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
(SELECT column_name
FROM table_name
WHERE condition);
Example 1: lists all the product names
SELECT ALL ProductName
FROM Products
WHERE TRUE;
Example 2: lists the ProductName if ALL the records in the OrderDetails table has Quantity equal to 10
SELECT ProductName
FROM Products
WHERE ProductID = ALL
(SELECT ProductID
FROM OrderDetails
WHERE Quantity = 10);
This post is based on W3School's articles about SQL.