I'm using SQL (SQL Server, PostgreSQL) over 10 years and still I'm never used ANY/SOME
and ALL
keywords in my production code. All situation I've encountered I could get away with IN
, MAX
, MIN
, EXISTS
, and I think it's more readable.
For example:
-- = ANY
select * from Users as U where U.ID = ANY(select P.User_ID from Payments as P);
-- IN
select * from Users as U where U.ID IN (select P.User_ID from Payments as P);
Or
-- < ANY
select * from Users as U where U.Salary < ANY(select P.Amount from Payments as P);
-- EXISTS
select * from Users as U where EXISTS (select * from Payments as P where P.Amount > U.Salary);
Using ANY/SOME
and ALL
:
So the question is: am I missing something? is there some situation where ANY/SOME
and ALL
shine over other solutions?
EXCEPT
either. I stick toNOT EXISTS
– GratiannaEXCEPT
is useful to find differences between two tables with same schema – Magdamagdaia= ANY
andIN
are alias for subqueries. So your first comparison doesn't make much sense actually, it's comparing the same thing with itself. – Sweeany
,some
andall
could be easily removed from the code – MagdamagdaiaEXCEPT
is an easy way to compare the results of twoSELECT
statements:SELECT … EXCEPT SELECT …
would yield an empty set of the results are the same. – Bonneau