If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Query: inner joins on two columns.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-06, 08:30
grooverinthesouth grooverinthesouth is offline
Registered User
 
Join Date: Mar 2006
Posts: 36
Question Query: inner joins on two columns.

Any help with this would be much appreciated.
My sql is fairly limited...

I have 2 tables.

Table1 = [id], [description]
This is used as a 'lookup table'
Example data =
1, poor
2, average
3, good

Table2 = [id], [workRelationship], [jobRelationship]

Example data =
342, 2, 1
452, 1, 3

Table 1 has a relationship to table 2 on [workRelationship] and [jobRelationship] on Table1.id

I'd like to form a select query that would return:
Table2[id] , [workRelationship].description, [jobRelationship].description
OR in laymans terms using data above:
342, Average, Poor
452, Poor, Good

with [workRelationship] producing the description from Table1 and not a number.Any Help would be much appreciated.
I have used an inner join but because there are two columns(workRelationship, jobRelationship) I only get one result.

Cheers.

Last edited by grooverinthesouth; 09-27-06 at 08:34.
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 11:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select Table2.id
     , wrkRel.description as wrkRel_descr
     , jobRel.description as jobRel_descr
  from Table2
inner
  join Table1 as wrkRel
    on wrkRel.id = Table2.workRelationship
inner
  join Table1 as jobRel
    on jobRel.id = Table2.jobRelationship
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On