ANY and ALL
ANY is true if the comparison holds for at least one value of the subquery, and ALL if it holds for every value. They are written after a comparison operator. SQLite does not have them, so the same ideas can be written with MIN, MAX or IN.
Example
SELECT name FROM students
WHERE score > ALL (SELECT score FROM students WHERE country = 'Ghana');
-- same result in SQLite and other databases
SELECT name FROM students
WHERE score > (SELECT MAX(score) FROM students WHERE country = 'Ghana');Example
SELECT name
FROM students
WHERE score > (SELECT MAX(score) FROM students WHERE country = 'Ghana')
ORDER BY name;Result
name Ada Amina Zainab
- ANY and ALL work in MySQL, PostgreSQL and SQL Server, but not in SQLite.
Exercise
True if the value beats every result.
WHERE score > (SELECT score FROM students)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.