Pages

How to use SQL ANY, SOME, ALL?

ANY, SOME, ALL keywords are used at WHERE part of SQL statements to compare values with set of values.

Example: Get list of students had got grade more than 50 or 70.

SELECT name, grade FROM students WHERE grade > ANY(50, 70)
;
SELECT name, grade FROM students WHERE grade > SOME(50, 70);

Get list of students had got grade more than both 50 and 70.

SELECT name, grade FROM students WHERE grade > ALL(50, 70)
;

No comments:

Post a Comment