How to do an INNER JOIN on multiple columns

前端 未结 5 2066
春和景丽
春和景丽 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:28

    if mysql is okay for you:

    SELECT flights.*, 
           fromairports.city as fromCity, 
           toairports.city as toCity
    FROM flights
    LEFT JOIN (airports as fromairports, airports as toairports)
    ON (fromairports.code=flights.fairport AND toairports.code=flights.tairport )
    WHERE flights.fairport = '?' OR fromairports.city = '?'
    

    edit: added example to filter the output for code or city

提交回复
热议问题