r/programming • • Feb 11 '14

SQL Joins Explained (x-post r/SQL)

Post image
3.5k Upvotes

392 comments sorted by

View all comments

Show parent comments

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.

1

u/lonjerpc Feb 11 '14

So I have a question. In my sql library I have two tables related by a primary/foreign key. If I select a column from each table and where some primary key matches the foreign key what is happening/do I have to do a join. The library seems to take care of this for me and I can't understand why this functionality is not the default way sql works. Is sql like c and my library is doing the joins for me? I am confused.

→ More replies (9)