ANY and ALL compare a value with every value returned by a subquery:
Price > ANY (subquery): greater than at least one value.
Price > ALL (subquery): greater than every value.
These work in MySQL, PostgreSQL and SQL Server. SQLite does not support them, but MIN() and MAX() give the same results, as the example shows:
> ANY (...) is the same as > (SELECT MIN(...))
> ALL (...) is the same as > (SELECT MAX(...))
💡 Key Takeaways: SQL ANY & ALL
Mastering SQL ANY & ALL helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SQL ANY & ALL Code Example
SQL
-- Products more expensive than ALL furniture (= > ALL)
SELECT ProductName, Price FROM Products
WHERE Price > (SELECT MAX(Price) FROM Products WHERE Category = 'Furniture');
-- Products more expensive than ANY furniture (= > ANY)
SELECT ProductName, Price FROM Products
WHERE Price > (SELECT MIN(Price) FROM Products WHERE Category = 'Furniture');
Free sign-in required · Google login available
SQL ANY & ALL Practice Exercises
Check what you learned in “SQL ANY & ALL”.
/ 3 solved
Fill in the blank
In SQLite, "> ALL (subquery)" can be written with this aggregate.
WHERE Price > (SELECT (Price) FROM Products WHERE Category = 'Stationery')
✓ Correct!Not quite. Try again.
Multiple choice
What does "> ANY (subquery)" mean?
✓ Correct!Not quite. Try again.
Code challenge
Select ProductName of products more expensive than ALL Electronics products except the Laptop (use MAX over Electronics where ProductName <> 'Laptop'), sorted by ProductName.
Write the code in the live editor. Your answer is checked automatically.