SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

fchachar
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 = worker.id

please suggest.

Thanks.

sunitabeck
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  w1.id = wi.assignedtoid
       LEFT JOIN worker w2
            ON  w2.id = wi.assignedbyid
Go to Top of Page

fchachar
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  
 New 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.08 seconds. Powered By: Snitz Forums 2000