Multiple join in mysql
I am trying to开发者_如何学Go do a multiple join like this
SELECT * FROM (((Customer FULL JOIN Booking ON Customer.ID = Booking.CustID)
FULL JOIN Flight ON Booking.FlightID = Flight.ID)
FULL JOIN FlightRoute ON Flight.RouteID = FlightRoute.ID)
But it is syntactically incorrect according to mysql. Please help
There is no FULL JOIN
in MySQL. It's convoluted but a FULL JOIN
is equivalent to a UNION ALL
between a LEFT JOIN
and a RIGHT JOIN
, using a condition to remove duplicates. It's late in the day and the thought of your 3 FULL JOIN
s in that statement is hurting my head.
You do say in Conrad Frix's answer that removing the FULL
makes it work, if it does then you have misunderstood how FULL JOIN
s and INNER JOIN
s work.
For the first FULL JOIN
it would look like:
SELECT * FROM Customers c
LEFT JOIN Booking b ON c.ID = b.CustId
UNION ALL
SELECT * FROM Customers c
RIGHT JOIN Booking b ON c.ID = b.CustId
WHERE c.ID IS NULL
Use that basis to form the rest of your statements.
When i was looking about MySql and FULL Join i found this article which explains a number of ways to emulate FULL JOIN in Mysql. I think it could be usefull to you.
How to simulate FULL OUTER JOIN in MySQL
MySQL isn't my area of expertises but I don't think MySQL supports full joins. I found a simple article that details some alternatives.
http://www.xaprb.com/blog/2006/05/26/how-to-write-full-outer-join-in-mysql/
精彩评论