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 🙂
For some of the ones that weren’t explained by Matthew’s post:
Simple Join – A non explicit join, it defaults to an inner join
Natural Join – This does an inner join on all columns with the same name
Self Join – This is joining a table to itself, it can any other type of join (inner self join, outer self join, etc)
Cartesian join – This is every possible combination of rows, you’ll always end up with the product of the number of rows from both tables. You do it with an inner join without specifying a join condition
Cross join – This is a synonym for a Cartesian join
Inner Join with USING Clause – This is an alternate syntax for join conditions, you can use it if both tables have matching column names
Inner Join with ON Clause – This is the same as what I showed for a simple join, the only other syntax is to join in the where clause (as below)
Left Outer Join – Same as a left join
Right Outer Join – Same as a right join. It’s like a left join, but you get nulls on the first table rather than the second one