Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting same field to 2 different places in one query

Status
Not open for further replies.

bcahillane

Technical User
Nov 15, 2006
4
US
Here is a simplified view of the tables and fields relevant to my query:


Table: Workorder
Fields: workorderid (key), requesterid

Table: Workorderstate
Fields: workorderid (key), technicianid

Table: User
Fields: userid(key), name

Workorder and Workorderstate are related by workorderid. Requesterid is related to userid. Technicianid is also related to userid. I am bound to using this table and relation structure.

I would like a query that pulls all workorderid's and lists the related technician's name and requester's name. My problem is that I do not know how to pull the name field from user twice in one query where one instance refers to the technician and another refers to the requester.
 
looks like it might have been removed from the ANS SQL forum
Code:
select WO.workorderid
     , R.name as requestor
     , T.name as technician
  from Workorder as WO
inner
  join Workorderstate as WOS
    on WOS.workorderid = WO.workorderid
inner
  join User as R
    on R.userid = WO.requesterid
inner
  join User as T
    on T.userid = WOS.technicianid

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top