Survey: Join Predicate Order

It’s a quiet month as we look forward to 2016, so I’m asking a series of survey questions for the next few posts.

My first one is about the order of join predicates.

When joining two or more tables in T-SQL, which do you prefer?

SELECT *
FROM TableA a
INNER JOIN TableB b
   ON a.Col1 = b.Col1

or

SELECT *
FROM TableA a
INNER JOIN TableB b
   ON b.Col1 = a.Col1

The SQL Server Query Optimizer doesn’t care, so it comes down to your preference.

For legibility, I prefer the first option, where the table order is reflected in the predicate order.

Some people like having the order reversed.

Which do you prefer, and why?

Author: randolph

Randolph West is a Microsoft Data Platform MVP, and has worked with SQL Server since the late 1990s. When not consulting, he can be seen acting on the stage and screen, or doing voices for independent video games. Randolph is available for talks on SQL Server, and technology in general. He also offers training for junior DBAs. Connect with Randolph on Google+ or Twitter.