开发者

How can I do a FULL JOIN of MULTIPLE TABLES in MySQL

开发者 https://www.devze.com 2023-03-07 23:06 出处:网络
we have been searching for it but all we see is 2 table开发者_开发知识库s by the left and right inner/outer joins.

we have been searching for it but all we see is 2 table开发者_开发知识库s by the left and right inner/outer joins.

I love you guys.


MySQL doesn't support FULL OUTER JOIN.

As you mention, you can simulate a FULL OUTER JOIN of two tables using a combination of LEFT and RIGHT OUTER joins.

SELECT * FROM tableA LEFT JOIN tableB ON tableA.b_id = tableB.id
UNION ALL
SELECT * FROM tableA RIGHT JOIN tableB ON tableA.b_id = tableB.id
WHERE tableA.b_id IS NULL

The same technique can in theory be extended to more than two tables. I'd suggest first using the above approach to join two of the tables as a view. Then use the same approach again to join the view to the third table.


I don't know what to say about the love part, but

Having tables named a and b:

SELECT a.*, b.* FROM a, b

Does this the trick?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号