Getting ANY of the data

  • Comments posted to this topic are about the item Getting ANY of the data

  • Why would you want to code this as an  ANY?  Why not code it with the IN?

    WHERE bc.BeerName IN (SELECT b2.BeerName FROM dbo.Beer AS b2);

    -------------------------------------------------------------
    we travel not to escape life but for life not to escape us
    Don't fear failure, fear regret.

  • I'll admit I was struggling a bit to wrap a question around ANY. Suggestions welcome.

  • I never knew ANY Or SOME were an option, and after reading the description I don't think I would ever code it with these.  I would just use the IN.  Not sure why we need more than one way to do the same thing.

     

    -------------------------------------------------------------
    we travel not to escape life but for life not to escape us
    Don't fear failure, fear regret.

  • I think that ANY,  SOME and ALL have the advantage that you can use comparisons like less than or greater than. Imagine the Beer table has cost and a country columns, maybe this would show the beers that are more expensive than the average beer costs of any/all countries.  I'm sure there's a useful example somewhere but this is the best I could come up with.

    SELECT  a.*
    JOIN dbo.Beer AS a
    WHERE a.Cost > ANY
    --WHERE a.Cost > ALL
    ( SELECT AVG(Cost)
    FROM dbo.Beer
    GROUP BY Country)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply