How to do an INNER JOIN on multiple columns

前端 未结 5 2069
春和景丽
春和景丽 2020-11-30 16:57

I\'m working on a homework project and I\'m supposed to perform a database query which finds flights either by the city name or the airport code, but the flights

5条回答
  •  没有蜡笔的小新
    2020-11-30 17:40

    If you want to search on both FROM and TO airports, you'll want to join on the Airports table twice - then you can use both from and to tables in your results set:

    SELECT
       Flights.*,fromAirports.*,toAirports.*
    FROM
       Flights
    INNER JOIN 
       Airports fromAirports on Flights.fairport = fromAirports.code
    INNER JOIN 
       Airports toAirports on Flights.tairport = toAirports.code
    WHERE
     ...
    

提交回复
热议问题