Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006
    Posts
    36

    Question Unanswered: 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 09:34.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •