Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2001

    Unanswered: SQL WHERE Clause Order

    Does SQL Server execute filter conditions in the order given?

    For example,

    "SELECT * FROM table WHERE customerID=268 AND item_description LIKE '%pants%';"

    Does SQL Server first filter by customerID and then look for "pants" in the remaining records?

    If not, how can I force SQL Server to execute filter conditions in a particular order?

  2. #2
    Join Date
    Apr 2002
    First, it selects * from table, then the where condition applies.
    Click CTRL+L to see the execution plan.

  3. #3
    Join Date
    Feb 2002
    Your assumtions are correct.

    First it selects all, based on your first parameter value, then it checks the result based on your second value. If using "AND" both params must be valid.. (of topic hehe)

    But yes, its in the order you think it is

    Take care!

  4. #4
    Join Date
    Apr 2002

    U can use HINTS like (INDEX = indexname) to force system to look for a desired index. In you case it will be good to have index on CustomerId. Since SQL will not use index in case of LIKE clause starting with a wildcard character

    Best of luck
    Deepak Khattar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts