×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SQL join help needed
2

SQL join help needed

SQL join help needed

(OP)
hi there,
I have an airport table like this:

************
airports
------------
air_id
air_code
air_name
***********

and a flight table:

************
flight
------------
fl_id
fl_code
fl_depart_airport_id
fl_arrive_airport_id
***********

i need the select statement to get names for departure and arrivel airports. something like this:

***********************
fl_code
departure_airport_name
arrival_airport_name
***********************
any help much appreciated

RE: SQL join help needed

CODE

SELECT fl_code,
  (select depart.airport_name
   FROM airports depart
   WHERE depart.fl_id = flights.fl_id) As DepartureAirport,

  (select arrive.airport_name
   FROM airports arrive
   WHERE arrive.fl_id = flights.fl_id) As ArrivalAirport,
FROM flights

John

RE: SQL join help needed

If the solution above, with sub-queries, turns out to be too slow, try this instead:

SELECT fl_code,
       depart.air_name,
       arrive.air_name
FROM flight,
     airports AS depart,
     airports AS arrive
WHERE depart.air_id = fl_depart_airport_id
AND   arrive.air_id = fl_arrive_airport_id

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close