Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

we have been searching for it but all we see is 2 tables by the left and right inner/outer joins.

I love you guys.

like image 374
jan estepa Avatar asked May 23 '11 09:05

jan estepa


1 Answers

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.

like image 194
Mark Byers Avatar answered Sep 28 '22 04:09

Mark Byers