Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql joins - Joining more than one table

I am trying to understand joins and im a bit confused. I know how to join tables using

=
<=

IN exists and not exists

I was trying to try and understand the use of INNER JOIN, LEFT OUTER JOIN, USING etc but it is so confusing. The major problem i am having is that different people refer to them using different names. Is there a simple explanation of the different types of joins and what other names they are known as. For example, while googling i came across the following types

♦ Simple Join
♦ Equi join
♦ Natural Join
♦ Outer Join
♦ Self Join
♦ Cartesian join
♦ Inner join
♦ Nonequi join
♦ Theta join
♦ Self join 
♦ Cross join
♦ Cross Joins
♦ Natural Joins
♦ Inner Join with USING Clause
♦ Inner Join with ON Clause
♦ Left Outer Join
♦ Right Outer Join
♦ Full OuterJoin

The majority of the above are duplicates, i.e. its the same type of join but with a different name. I am sure all the above can be recreated using one of (=, !=, not in, in exists etc) but I am struggling to undestand which is which and the difference between them. A diagram would probably help :)

like image 429
ziggy Avatar asked Dec 04 '22 10:12

ziggy


1 Answers

Jeff Atwood to the rescue

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

like image 192
Matthew Vines Avatar answered Dec 31 '22 11:12

Matthew Vines