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
 Multiple References of Table In a Record

Author  Topic 

boybles
Starting Member

23 Posts

Posted - 2008-07-05 : 17:01:06
I have a mail table that references an employee table twice for each record. How can I pull off the following?
Please Help!
Boybles


TABLES:
Employee
----------
EmployeeID (smallint)
EmployeeName (varchar)


Mail
----------
MailID (smallint)
MailName (varchar)
MailFrom (smallint)
MailTo (smallint)

SAMPLE DATA:
Employee
-------
1|Joe
2|Jane


Mail
-------
1|Test Mail|1|2


DESIRED RESULT:
(MailFromName, MailToName would be aliases)

MailName|MailFromName|MailToName
---------------------------------
Test Mail|Joe|Jane

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-05 : 21:29:38
[code]
select m.MailName, MailFromName = f.EmployeeName, MailTonName = t.EmployeeName
from Mail m
inner join Employee f on m.MailFrom = f.EmployeeID
inner join Employee t on m.MailTo = t.EmployeeID
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

boybles
Starting Member

23 Posts

Posted - 2008-07-06 : 21:16:01
Wonderful. Thanks for your help, Khtan!
Boybles
Go to Top of Page
   

- Advertisement -