ITeye博客

MySQL全连接(Full Join)实现

libin123 · 2012-07-09 18:18 · mysql · 数据库 · Markdown

MYSQL 可以用 union 实现全连接 mysql> select * from a; +------+ | id | +------+ | 1 | | 2 | | 3 | +------+ 3 rows in set (0.00 sec)

mysql> select * from b; +------+ | id | +------+ | 1 | | 2 | | 4 | +------+ 3 rows in set (0.00 sec)

mysql> select a.id,b.id from a left join b on a.id=b.id union select a.id,b.id f rom a right join b on a.id=b.id; +------+------+ | id | id | +------+------+ | 1 | 1 | | 2 | 2 | | 3 | NULL | | NULL | 4 | +------+------+ 4 rows in set (0.00 sec)

mysql>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。