Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 left outer join

Author  Topic 

mohdmartin
Starting Member

22 Posts

Posted - 2007-09-04 : 09:43:48
How can user left outer join with three tables ?
it retreive all employees name if position and department
are not found

fields
--------
department_code
position_code

position_code and department_code include in employee table


SELECT e.name,e.position_code
FROM employee e LEFT OUTER JOIN position p
ON e.position_code = p.position_code

regards
Mateen

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-09-04 : 10:00:40

SELECT e.name,e.position_code, d.department_code
FROM employee e
LEFT OUTER JOIN position p
ON e.position_code = p.position_code
LEFT OUTER JOIN department d
ON e.department_code = d.department_code


Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-09-04 : 10:02:47
Just add another left outer join statement:

SELECT e.name,e.position_code,d.department
FROM
employee e
LEFT OUTER JOIN
position p
ON
e.position_code = p.position_code
LEFT OUTER JOIN
department d
ON
<whatever links department to employee or position table>

Jim
Go to Top of Page

mohdmartin
Starting Member

22 Posts

Posted - 2007-09-04 : 10:03:11
Thanks you.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-04 : 10:03:34
Which is the third table?
SELECT e.name,e.position_code
FROM employee e LEFT OUTER JOIN position p
ON e.position_code = p.position_code
Left Join Dept d on e.DeptNo = d.DeptNo


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -