Archive for April 6th, 2009
Emulating FULL OUTER JOIN in MySQL
Comments enabled. I *really* need your comment
It is widely known that MySQL lacks support for FULL OUTER JOIN
.
A common solution to work around this is using a UNION ALL
to union two result sets from a LEFT JOIN
and a RIGHT JOIN
of two tables, adding join_column IS NULL
condition to the latter.
Though it works, it's quite inefficient on large tables when used with ORDER BY … LIMIT
queries, as it uses a filesort
.
Let's create two sample tables and OUTER JOIN
them together.
The tables are quite simple: each of them contains a million of multiples of 13 and 17, respectively, thus making each of LEFT JOIN
, RIGHT JOIN
and INNER JOIN
of these tables non-empty:
Read the rest of this entry »