`

MySQL全连接(Full Join)实现

 
阅读更多
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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics