Join with Multiple Tables

为君一笑 提交于 2019-12-11 06:26:43

问题


I am getting a syntax error with the following problem and can't seem to figure out, hope you guys can help me!

I have these tables (they are populated):

I am trying to retrieve the first and last name of all the passengers scheduled in a certain flight number so what I have is this:

SELECT PassFName, PassLName
FROM Passenger
INNER JOIN PassID ON Passenger.PassID = Reservation.PassID
INNER JOIN FlightNum ON FlightNum.Reservation = FlightNum.ScheduledFlight
WHERE ScheduledFlight.FlightNum = [Enter Flight Number];

However, I am getting error:

Not sure why and I have also noticed in the last line it is misspelling FlightNum.ScheduledFlight. Any idea what am I doing wrong?

Thank you!


回答1:


Gordon's point is valid, but he's got his parentheses misplaced and missed the other big issues. This query is more than a little whacked, with table names and field names flip-flopped. Here's what I would guess would work...

SELECT
       PassFName
     , PassLName
FROM (
     Passenger
     INNER JOIN Reservation
        ON Passenger.PassID = Reservation.PassID
     )
INNER JOIN ScheduledFlight
    ON Reservation.FlightNum = ScheduledFlight.FlightNum
WHERE
     ScheduledFlight.FlightNum = [Enter Flight Number];



回答2:


MS Access has a strange syntax for joins. It requires parentheses around each JOIN pair. So:

SELECT PassFName, PassLName
FROM (Passenger INNER JOIN
      Reservation
     ) ON Passenger.PassID = Reservation.PassID INNER JOIN
     FlightNum
     ON FlightNum.Reservation = FlightNum.ScheduledFlight
WHERE ScheduledFlight.FlightNum = [Enter Flight Number];

Although other databases support this syntax, it is only required in MS Access.



来源:https://stackoverflow.com/questions/47319916/join-with-multiple-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!