Search This Blog

Friday, April 24, 2009

ANYthing will do as EveryThing or All

I must admit i have never had to use the ANY and ALL keywords in my queries and i could not find any simple explanation. So here is my understanding of what differentiates them.
ANY, compares the result to ANY values
ALL, compares the result to ALL values.








Product CostProduct Name
5Apples
10Orange
20Banana


Query using ALL keyword will return
SELECT [Product Name] FROM Product WHERE [Product Cost] >= ALL
(SELECT MAX ([Product Cost]) FROM Product)
This query will return a value that is greater than the max value.

Below sample explanation is from MSDN which breaks it down nicely.
For example, >ALL (1, 2, 3) means greater than 3. >ANY means greater than at least one value, that is, greater than the minimum. So >ANY (1, 2, 3) means greater than 1.

No comments:

Post a Comment