Process Order in 'WHERE'

  • I read somewhere at some time that it's best to put your most-likely-to-fail comparison towards the 'front' so if it returns false, for an AND statement, the whole thing is false right away. I can't remember the direction of processing for comparison statements

    eg.

    ...

    WHERE T1.a = T2.a AND T1.b = T2.b

    which would process first, T1.a = T2.a or T1.b = T2.b?

    Thanks

    P.S. I tried to google this but "order" and "left" or "right" pulls back a ton of stuff about SQL

  • Thanks much!

  • There isn't a guaranteed sequence. SQL Server will decide how to resolve the query, and which sequence to apply Where statements in, based on how much work it thinks will be involved.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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