I am trying search for flights departing from London and Arriving in Paris. The information about the cities are located in the Airport table, while the abbreviations for the departing and arriving airports are located in Flight.
Here's my code for the problem:
SELECT flightNo,flightCompany
FROM Flight
JOIN Airport
ON Airport.airportId=Flight.depAirport
WHERE Airport.city='London'
INTERSECT
SELECT flightNo,flightCompany
FROM Flight
JOIN Airport
ON Airport.airportId=Flight.arrAirport
WHERE Airport.city='Paris';
It returns 3 errors -
How about re-writing the query using JOIN
s instead?
SELECT f.flightNo, f.flightCompany
FROM Flight f JOIN
Airport ad
ON ad.airportId = f.depAirport AND ad.city = 'London' JOIN
Airport aa
ON aa.airportId = f.arrAirport AND aa.city = 'Paris';
Or, using EXISTS
?
SELECT f.*
FROM Flight f
WHERE EXISTS (SELECT 1
FROM Airport ad
WHERE ad.airportId = f.depAirport AND ad.city = 'London'
) AND
EXISTS (SELECT 1
FROM Airport aa
WHERE aa.airportId = f.arrAirport AND aa.city = 'Paris'
);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加