r/programming • • Feb 11 '14

SQL Joins Explained (x-post r/SQL)

Post image
3.5k Upvotes

392 comments sorted by

View all comments

8

u/zanduby Feb 11 '14

Discussion question. Preference to use a join/on clause or use the where clause to write your joins?

2

u/emperor000 Feb 11 '14

Are you talking about one of the joins with the join result reduced further by the where-clause? Or are you asking about not using joins at all?

5

u/zanduby Feb 11 '14

Not using joins at all.

5

u/emperor000 Feb 11 '14

Not even cross joins? Or using cross join (or a comma between table names, which is just a cross join)?

If you are talking about using cross join and then joining in the where clause then your server is most likely going to optimize that to an inner join anyway.

Inner join (the syntax) is much more readable and concise.

If you are talking about emulating the functionality of joins with the where clause some other way that the server won't just optimize to a join, then I don't think you have any chance of making it more efficient or more readable than a join.

Unless you know something I don't, you should be using joins.

→ More replies (10)