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.
Author |
Topic |
fchachar
Starting Member
15 Posts |
Posted - 2012-09-24 : 14:45:40
|
HI, I have 2 tables that I have joined Table1: WorkItem Table2: WorkerWorkitem is the main table where Worker table contains information about the person such as name, userid etc. Workitem has two fields 1, Assigned by 2, Modified by both fields have userids.I want to capture the names Assigned by and Modified by.select * from workitemleft join worker on workitem.assignedtoid = worker.idplease suggest.Thanks. |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-09-24 : 14:51:35
|
You will need to join to the worker table twice:SELECT wi.*, w1.[name] AS AssignedToLastname, w2.[name] AS AssignedByLastnameFROM workitem wi LEFT JOIN worker w1 ON w1.id = wi.assignedtoid LEFT JOIN worker w2 ON w2.id = wi.assignedbyid |
|
|
fchachar
Starting Member
15 Posts |
Posted - 2012-09-24 : 15:14:45
|
Thanks alot Sunitabeck.. you're the best |
|
|
|
|
|