I’m wondering what the difference between the following queries (using two different join syntaxs) would be. I saw this in some code I was inherited and was curious if there outcome is always the same. And if not, why you would use one over the other.
Query #1 Example:
SELECT * FROM TableA a
INNER JOIN TableB b
INNER JOIN TableC c
ON b.TableBId = c.TableCId
ON b.TableBId = a.TableAId
Query #2 Example:
SELECT * FROM TableA a
INNER JOIN TableB b
ON b.TableBId = a.TableAId
INNER JOIN TableC c
ON b.TableBId = c.TableCId
As has already been stated, you can review the execution plans to verify that these are indeed the same queries. I am almost certain that they are, though
More to your question of why you would choose one over the other. I would say that this comes down to style preferences. Most of the time you will see Query #2 because it has a clearer definition for future readers. If you create a truly complicated query, then the benefit you gain grows tremendously.
I cannot really vouch for the other approach as I truly believe that it becomes too unreadable and should never be used. Again, that is my opinion and, the reasoning comes down to opinions/styles.
However, the standard way is query2, so I would stick with that :)…but again, just me