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:
![](https://www.praudyog.com/wp-content/uploads/2023/05/193-1024x445.jpg)
Order Table:
![](https://www.praudyog.com/wp-content/uploads/2023/05/194-1024x489.jpg)
Example-1:
SELECT ProductName
FROM Products
WHERE ProductID = ALL (SELECT ProductID FROM OrderDetails WHERE Quantity = 10);
![](https://www.praudyog.com/wp-content/uploads/2023/05/196.jpg)
Example-2:find teachers whose age is greater than all students, we can use
SELECT *
FROM Teachers
WHERE age > ALL (
SELECT age
FROM Students
);