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 getting results from a join

Author  Topic 

tpiazza55
Posting Yak Master

162 Posts

Posted - 2007-01-05 : 15:32:16


i have a query with some inner joins that return information about an employee

i am running into a problem in that i need one employees email based on one inner join and anothers based on another inner join -- is there a way to get both in one query?

select employee.email , bunch of other stuff
from work

INNER JOIN technician ON business_location.technician_id = technician.technician_id

inner join salesrep on business_location.salesrepid = salesrep.salesrep_id

not sure how to get both of those to employee.emp_id and get the email

technician.technician_id = employee.emp_id
salesrep.salesrep_id = employee.emp_id






snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-05 : 15:47:21
You haven't really given enough to go on, in the query you gave you have a table named work that you never use and another named business_location that you use in the joins without having introduced the table in the query first - so I'm guessing, but you can do what you want - just join the same table twice with aliases something like this

select E1.email , E2.email , bunch of other stuff
from work

INNER JOIN technician ON business_location.technician_id = technician.technician_id

inner join salesrep on business_location.salesrepid = salesrep.salesrep_id

inner join employee E1 on technician.technician_id = E1.emp_id

inner join employee E2 on salesrep.salesrep_id = E2.emp_id
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-05 : 19:00:14
Duplicate post of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=77171


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -