MySQL全连接(Full Join)实现
下面是一个简单测试,可以看看:
mysql> CREATE TABLE a(id int,name char(1));
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE b(id int,name char(1));
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO a VALUES(1,‘a‘),(2,‘b‘);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO b VALUES(2,‘b‘),(3,‘c‘);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM a LEFT JOIN b ON a.id=b.id
-> UNION
-> SELECT * FROM a RIGHT JOIN b ON a.id=b.id;
+------+------+------+------+
| id | name | id | name |
+------+------+------+------+
| 1 | a | NULL | NULL |
| 2 | b | 2 | b |
| NULL | NULL | 3 | c |
+------+------+------+------+
3 rows in set (0.00 sec)
mysql>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。