Select statement with WHERE clause

  • Sorry for naive question (it's so hot on the East Coast!)

    Query:

    SELECT * From myTbl WHERE A="20" and B="167"

    How the engine is going to process:

    1. select all A's and then B's

    2. select all B's and then A's

    3. None of the above (but how?)

    Thanks

  • valeryk2000 (6/28/2010)


    Sorry for naive question (it's so hot on the East Coast!)

    Query:

    SELECT * From myTbl WHERE A="20" and B="167"

    How the engine is going to process:

    1. select all A's and then B's

    2. select all B's and then A's

    3. None of the above (but how?)

    Thanks

    Not sure what your question is exactly, but I will try to help. It's important to keep in mind that SQL Server is not procedural in the nature of processing in the way that we tend to think about doing X then Y.

    The end result is that it will select records where both conditions are true. How it's going to go about doing that is dependent on your indexes, size of the table, etc. Ultimately, it will use the best index available and if no good indexes are available the result of the query will be a table scan and each record will be evaluated for both conditions.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • To add to what BT said, SQL is Cost Based. So, how the optimizer does it business is based on the perceived cost (this cost could be out of whack if statistics are off). Here is a link that talks about it in more depth:

    http://www.qdpma.com/SQLServerCostBasedOptimizer.html

  • Thanks.

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

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