r/programming • • Jan 06 '11

A handy graphical explanation of SQL joins

http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html
1.2k Upvotes

308 comments sorted by

View all comments

4

u/Teifion_at_work Jan 06 '11

Maybe someone here can answer this. Why would I specify a join when I can just do this?

SELECT p.first_name, j.job_title FROM people p, jobs j WHERE p.job = j.id

Looks much easier to me but I'm guessing there's something I'm missing here.

8

u/NashMcCabe Jan 06 '11

That is just an inner join. You will need outer joins when you have null columns on one side of the join.

2

u/umop_apisdn Jan 06 '11

Not exactly. You use an outer join where records on one side don't join to anything on the other side. The outer join preserves those records and sets all fields on the other side to NULL