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 > Database Server Software > MySQL > join 2 columns of a table with a column from another table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-10, 18:19
tnijenbrink tnijenbrink is offline
Registered User
 
Join Date: Jan 2010
Posts: 2
Question 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?
Reply With Quote
  #2 (permalink)  
Old 01-17-10, 19:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-18-10, 03:25
tnijenbrink tnijenbrink is offline
Registered User
 
Join Date: Jan 2010
Posts: 2
Got it, thanks!

That worked, thanks a lot.
Reply With Quote
Reply

Tags
joins

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