MySQL本身不支持你所说的full join(全连接),但可以通过union来实现 ,
下面是一个简单测试,可以看看:
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>
参考:
阅读(32163) | 评论(0) | 转发(0) |