views:

952

answers:

9

What is the difference between an inner join and outer join? What's the precise meaning of these two kinds of joins?

A: 

INNER JOIN returns rows that exist in both tables

OUTER JOIN returns all rows that exist in either table

Galwegian
inner join returns values from both tables if the join condition exists in both tables....
marc_s
+4  A: 

Wikipedia has a nice long article on the topic here

But basically :

  • Inner joins return results where there are rows that satisfy the where clause in ALL tables
  • Outer joins return results where there are rows that satisfy the where clause in at least one of the tables
Glen
+18  A: 

Check out Jeff Atwood's excellent:

A Visual Explanation of SQL Joins

INNER JOIN

alt text

LEFT OUTER JOIN

alt text

Marc

marc_s
I would show outer join: KISS.
Ewan Todd
awesome!thanks!
freenight
A: 

Wikipedia to the rescue:

Inner Joins

Outer Joins

Trevor
+2  A: 

You use INNER JOIN to return all rows from both tables where there is a match. ie. in the resulting table all the rows and columns will have values.

In OUTER JOIN the resulting table may have empty columns. Outer join may be either LEFT or RIGHT

LEFT OUTER JOIN returns all the rows from the first table, even if there are no matches in the second table.

RIGHT OUTER JOIN returns all the rows from the second table, even if there are no matches in the first table.

Mick Walker
A: 

Inner join only returns a joined row if the record appears in both table. Outer join depending on direction will show all records from one table, joined to the data from them joined table where a corresponding row exists

Kris C
A: 

See the following explanations from MSDN:

Using Inner Joins

Using Outer Joins

MatthieuF
A: 

Using mathematical Set,

Inner Join is A ^ B;
Outer Join is A - B.

So it is (+) is your A side in the query.

DKSRathore