Which SQL query is faster? Filter on Join criteria or Where clause?

Posted by Jon Erickson on Stack Overflow See other posts from Stack Overflow or by Jon Erickson
Published on 2010-03-24T17:33:48Z Indexed on 2010/03/24 17:43 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

Compare these 2 queries. Is it faster to put the filter on the join criteria or in the were clause. I have always felt that it is faster on the join criteria because it reduces the result set at the soonest possible moment, but I don't know for sure.

I'm going to build some tests to see, but I also wanted to get opinions on which would is clearer to read as well.

Query 1

SELECT      *
FROM        TableA a
INNER JOIN  TableXRef x
        ON  a.ID = x.TableAID
INNER JOIN  TableB b
        ON  x.TableBID = b.ID
WHERE       a.ID = 1            /* <-- Filter here? */

Query 2

SELECT      *
FROM        TableA a
INNER JOIN  TableXRef x
        ON  a.ID = x.TableAID
        AND a.ID = 1            /* <-- Or filter here? */
INNER JOIN  TableB b
        ON  x.TableBID = b.ID

© Stack Overflow or respective owner

Related posts about sql

Related posts about t-sql