I am trying to write a query that determines which cities I cannot fly directly from the city, say, to London. Given the scheme:
cities:
| c_id | city_name |
flights:
| f_id | departure_city_id | destination_city_id |
currently my query returns the opposite, i.e. returns cities for which there is a direct flight from London
SELECT c2.city_name as "City" FROM flights AS f JOIN cities AS c2 ON f.destination_city_id != c2.c_id JOIN cities AS c ON c.c_id = c.c_id WHERE c.city_name = 'London' AND c.c_id != c2.c_id AND f.departure_city_id = c.c_id;
I would have thought it would be easy to change it to get what I want. I thought to change the third line to
JOIN cities AS c2 ON f.destination_city_id = c2.c_id
Would do the trick, but itβs not. Any help?
source share