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
 Problem in join

Author  Topic 

Tamer
Starting Member

22 Posts

Posted - 2008-08-27 : 05:25:58
Dear Experts,

I have problem in linking a table with two tables by join,

I have these tables followed by their fields:

1-Employee :e_no,e_name1,e_dept,e_job
2-Dept :c_no,c_name
3-Job :c_no,c_name

I would get this result
select e.e_no,e.e_name,d.c_name,j.c_name
from employee e , dept d , job j

this need to link twice , e.e_dept=d.c_no and e.e_job=j.c_no

If I use the the where clause it wont bring the employees without
dept and job numbers in the main employee table

How can use the join in this issue

Thanks In Advance

Tamer

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-27 : 05:31:41
use left join

select e.e_no,e.e_name,d.c_name,j.c_name 
from employee e
left join dept d
on e.e_dept=d.c_no
left join job j
on e.e_job=j.c_no

Go to Top of Page

Tamer
Starting Member

22 Posts

Posted - 2008-08-27 : 05:38:44
Thank you very much Mr.

It works fine
Go to Top of Page
   

- Advertisement -