2016-10-01 74 views
0

我有一個查詢,我在MySQL中運行,它使用別名從同一列中獲取信息兩次(來自airport表的目標)。查詢結果在使用別名時顯示兩次?

`SELECT AirlineName AS 'Airline Name', 
    airport1.AirportName AS 'Flying From', 
    airport2.AirportName AS 'Flying To', 
    StopType AS 'Number of Stops' 
FROM flightjunction 
INNER JOIN airline ON flightjunction.FlightAirline = airline.AirlineID 
INNER JOIN airport AS airport1 ON flightjunction.FlightFrom = airport1.AirportID 
INNER JOIN airport AS airport2 ON flightjunction.FlightTo = airport2.AirportID 
INNER JOIN stops ON flightjunction.FlightStops = stops.StopID;` 

但是,我注意到當我運行此查詢時出現重複的結果。我哪裏錯了?預先感謝您的幫助!

+0

請參閱http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple- sql-query – Strawberry

回答

1

由於在這種情況下,您在同一個表上有兩次內部聯接,所以應該添加一個DISTINCT以消除重複項。

+0

哦,那很好用!謝謝你,numX! – Anakela

+0

乾杯,請設置爲接受的答案,如果這解決了你的問題:) – numX