Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Joining 2 tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

15 Posts

Posted - 09/24/2012 :  14:45:40  Show Profile  Reply with Quote
HI, I have 2 tables that I have joined

Table1: WorkItem
Table2: Worker

Workitem 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 workitem
left join worker on workitem.assignedtoid =

please suggest.


Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/24/2012 :  14:51:35  Show Profile  Reply with Quote
You will need to join to the worker table twice:
SELECT wi.*,
       w1.[name]  AS AssignedToLastname,
       w2.[name]  AS AssignedByLastname
FROM   workitem wi
       LEFT JOIN worker w1
            ON = wi.assignedtoid
       LEFT JOIN worker w2
            ON = wi.assignedbyid
Go to Top of Page

Starting Member

15 Posts

Posted - 09/24/2012 :  15:14:45  Show Profile  Reply with Quote
Thanks alot Sunitabeck.. you're the best
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000