SQL ALL Keyword
Table Of Contents:
- What Is SQL All Keyword?
- Syntax Of SQL All Keyword.
- Examples Of SQL ALL Keyword.
(1) What Is SQL All Keyword?
- The
ALL
operator: returns a boolean value as a result. - The
ALL
operator: returns TRUE if ALL of the subquery values meet the condition. - The
ALL
operator: is used withSELECT
,WHERE
andHAVING
statements.
(2) Syntax Of SQL All Keyword.
SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
(SELECT column_name
FROM table_name
WHERE condition);
Note:
- The operator must be a standard comparison operator (=, <>, !=, >, >=, <, or <=).
(3) Examples Of SQL All Keyword.
Product Table:
Order Table:
Example-1:
SELECT ProductName
FROM Products
WHERE ProductID = ALL (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);
Example-2:find teachers whose age is greater than all students, we can use
SELECT *
FROM Teachers
WHERE age > ALL (
SELECT age
FROM Students
);