skip to Main Content

I need to display the departure and arrival airport codes with their names from another table. But I don’t know how to do this in one request

select flight_no, a.departure_airport, b.airport_name from flights a
join airports_data b on a.departure_airport = b.airport_code
select flight_no, a.arrival_airport, b.airport_name from flights a
join airports_data b on a.arrival_airport = b.airport_code

2

Answers


  1. You can join the tableairport_data twince

    select flight_no, a.arrival_airport, b.airport_name as arrival_airport_name , a.departure_airport, b.airport_name as departure_airport_name from flights a
    join airports_data b on a.departure_airport = b.airport_code
    Join airports_data c on a.arrival_airport = c.airport_code
    
    Login or Signup to reply.
  2. You can join airports_data as b and c and then use the fields of a, b and c, you can also rename airport_name inside your select clause to differentiate between b and c

    select flight_no, a.departure_airport, a.arrival_airport, b.airport_name b_name, c.airport_name as c_name from flights a
    join airports_data b on a.departure_airport = b.airport_code
    join airports_data c on a.arrival_airport = c.airport_code
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search