Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Question Unanswered: join 2 columns of a table with a column from another table

    Hello,

    I have got a table 'transport' with amongst others two columns:
    transport.company_from
    transport.company_to

    And a table 'companies' that holds information about companies. For a list I need to extract the names of the companies in a set of records from the 'transport' table in a single query.

    I have no idea how to go about this.

    Anyone know?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT transport.amongst
         , transport.others
         , from_co.name AS from_company
         , to_co.name AS to_company
      FROM transport
    INNER
      JOIN companies AS from_co
        ON from_co.id = transport.company_from
    INNER
      JOIN companies AS to_co
        ON to_co.id = transport.company_to
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Got it, thanks!

    That worked, thanks a lot.

Tags for this Thread

Posting Permissions

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