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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple joins in each record

Status
Not open for further replies.

moBassman

IS-IT--Management
Jul 19, 2007
2
GB
HI - I'm a relatively inexperienced SQL newbie but need to do the following ...

I have two mysql tables:

tbl_clients
which includes fields: mgr and sp

the above two fields store the ids of emps
e.g
mgr 2
sp 3

and
tbl_emps
which includes fields: emp_id, emp_fname
e.g
1 Fred
2 Sue
3 Bert

I need to construct a SQL query that returns the names in place of the emp ids. e.g:

mgr Sue
sp Bert

anyone advise?





 
Hi

Code:
[b]select[/b]
c.*,
m.emp_fname [b]as[/b] mgr,
s.emp_fname [b]as[/b] sp

[b]from[/b] tbl_clients [b]as[/b] c
[b]inner join[/b] tbl_emps [b]as[/b] m [b]on[/b] m.emp_id=c.mgr
[b]inner join[/b] tbl_emps [b]as[/b] s [b]on[/b] s.emp_id=c.sp

Feherke.
 
many thanks for your response - I will try asap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top