Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

different between inner join, left join and left outer join

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys,

I'm just abit confuse between those two joins, I need your guys idea if I could :
Here's the example
Code:
SELECT Employees.Name, Orders.Product
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

-- result :
Name                Product 
Hansen, Ola         Printer 
Svendson, Stephen   Table 
Svendson, Stephen   Chair 

SELECT Employees.Name, Orders.Product
FROM Employees
LEFT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

--result
Name               Product 
Hansen, Ola        Printer 
Svendson, Tove   
Svendson, Stephen  Table 
Svendson, Stephen  Chair 
Pettersen, Kari

As you can see the inner join only shows whatever if first table and second table match.
But the left joins only shows whatever exists in first table, don't care whether exist in second table.

So, what's the difference with left outer join then ?
I thought left outer join would do the same as left join for example above.

Can anyone throws more idea please ?
 
Hokky, left and right joins are both outer joins in that they do not require each record in the 2 tables to having matching records.

Why... are you seeing different results?

Nick
 
you already understand the difference:
As you can see the inner join only shows whatever if first table and second table match.
But the left joins only shows whatever exists in first table, don't care whether exist in second table.

LEFT JOIN is the same as LEFT OUTER JOIN

the OUTER keyword is optional


r937.com | rudy.ca
 
... not to mention
RIGHT (OUTER) JOIN
FULL JOIN
CROSS JOIN

and at a deeper level,

LOOP
HASH
MERGE

from which we could get

INNER LOOP JOIN
INNER HASH JOIN
INNER MERGE JOIN
LEFT LOOP JOIN
LEFT HASH JOIN
LEFT MERGE JOIN
...


[COLOR=black #e0e0e0]For SQL and technical ideas, visit my blog, Squared Thoughts.

The best part about anything that has cheese is the cheese.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top