r/SQL • • Feb 11 '14

SQL Joins Explained

http://imgur.com/1m55Wqo
157 Upvotes

27 comments sorted by

View all comments

Show parent comments

4

u/fazzah Feb 11 '14

Agreed. Also, isn't the JOIN clause better for optimization? I've read somewhere that it's better for the optimizer to check the relation between rows before filtering the results with WHERE clause, because a simple WHERE condition to join tables produces a cartesian result which is THEN filtered.

3

u/askur Feb 11 '14

I've read similar things, and used to be of that opinion because of how queries are processed. However, I've never seen any meaningful results from it in my experience.

That of course only means that I haven't bothered to look deeper than just that. However, because of how dangerous it is to mix up the ON conditions VS WHERE conditions when you do an OUTER join of some kind, I just keep this theory to myself rather than confuse anyone.

4

u/fazzah Feb 11 '14

Even if there are no noticeable dis/advantages, it's still better to stick with the more readable one, the JOIN clauses.

2

u/sp00ks Feb 11 '14

I guess one advantage when updating a row, using WHERE prevents you from accidently calling a full join and updating everything!

2

u/fazzah Feb 11 '14

UPDATES are quite a different beast.

I always triple check my joined updates.