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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two field with same foreign key

Status
Not open for further replies.

ingiB

Programmer
May 7, 2007
1
US
I have two table: flight_info and cities

flight_info has fields:
flightNo Source Destination
125 1 4
432 5 2
777 6 3

cities has:
cityID Name
1 London
2 Dublin
3 Paris
4 Chicago
5 New York
6 Boston

Source and Destination are both foreign keys for cityID in cities.

I want to show
FlightNo Source Destination
125 London Chicago

I can get
flightNo Source(name)
125 London

but I'm having trouble with joining destination to the same thing as source.

Any advice????
 
Use TWO instances of the cities table with aliasing:
SELECT F.flightNo, S.Name Source, D.Name Destination
FROM flight_info F
INNER JOIN cities S ON F.Source = S.cityID
INNER JOIN cities D ON F.Destination = D.cityID

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top