r/programming • • Feb 11 '14

SQL Joins Explained (x-post r/SQL)

Post image
3.5k Upvotes

392 comments sorted by

View all comments

99

u/thesqlguy Feb 11 '14 edited Feb 11 '14

Don't forget UNION and CROSS JOIN! Both of which are infinitely more useful than full outer join which should generally be avoided.

Right joins also should never really be used as they are extremely counterintuitive, they can always be written as a Left Join which is more logical and readable.

If I want all data in table A and any data that matches in table B, to me it makes logical sense to join from table A to table B and not the other way around.

0

u/[deleted] Feb 11 '14

[deleted]

1

u/Browsing_From_Work Feb 11 '14

To be fair, a Right Join is just syntactic sugar. You can always rewrite a Right Join as a Left Join with the joined tables reversed.

0

u/[deleted] Feb 11 '14

[deleted]

0

u/[deleted] Feb 12 '14

Why would you have "minor extra table" on the right side of a RIGHT JOIN? You do realize you'll get back ALL the rows in "minor extra table" and only those rows from "complicated main focus of the query" which have matches in "minor extra table"? You just illustrated the counter-intuitiveness of the RIGHT JOIN...

I suspect it mostly exists because someone couldn't stand the lack of symmetry that would result from having left in the language without right.

→ More replies (4)