Performance-wise, they are the same (and produce the same plans)
Logically, you should make the operation that still has sense if you replace INNER JOIN
with a LEFT JOIN
.
In your very case this will look like this:
SELECT *
FROM TableA a
LEFT JOIN
TableXRef x
ON x.TableAID = a.ID
AND a.ID = 1
LEFT JOIN
TableB b
ON x.TableBID = b.ID
or this:
SELECT *
FROM TableA a
LEFT JOIN
TableXRef x
ON x.TableAID = a.ID
LEFT JOIN
TableB b
ON b.id = x.TableBID
WHERE a.id = 1
The former query will not return any actual matches for a.id
other than 1
, so the latter syntax (with WHERE
) is logically more consistent.