• DataAnalyst011 (12/17/2012)


    Again this is really helpful. I hope you all won't mind a follow-up question:

    What is the difference between...

    WHERE [column] IN ([subquery])

    and

    WHERE EXISTS ([subquery])

    ?

    I've been trying to read on it and trying queries on my test server but can't come up with anything helpful. Would someone mind explaining? I want to be able to support my code 🙂

    In the first case, the WHERE clause is true if the [column] exists in any of the rows returned by the subquery.

    In the second case, the WHERE clause is true if any rows are returned by the subquery.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St