question

SimonHolzman avatar image
SimonHolzman asked

Does the Table order in the ON clause matter in LEFT and RIGHT JOINs ?

Basically, are the following two Statement functionally identical or not ?

SELECT <fields>
FROM TableOne a
	LEFT OUTER JOIN TableTwo b ON a.JoinColumn = b.JoinColumn
SELECT <fields>
FROM TableOne a
	LEFT OUTER JOIN TableTwo b ON b.JoinColumn = a.JoinColumn

I tend to use the first version but, since I sometimes need a "AND b.OtherColumn = 'XXX'" clause, it seems more consistent to use the second version so that the table order matches.

I'm pretty sure that I qualify as a SQL expert with 30+ years experience and I am pretty sure that the ON clause order does NOT matter, but I thought I should double check.

sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered

Those two are executed exactly the same.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@Magnus Ahlkvist, Thanks. I thought so but...

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.