问题
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