日期:2014-05-16  浏览次数:20991 次

mysql里使用union
mysql里使用union对多个表进行联合
select语名1 union (select语句2 union select语句3)
使用括号改变执行顺序会报错 是不是不支持

还有一个问题
mysql哪个版本以后支持完全联接 (full)

多谢

------解决方案--------------------
给你看一个明显的。上面的不明显


SQL code

mysql> delete from t2 where id = 5;
Query OK, 1 row affected (0.00 sec)
mysql> delete from t1 where id = 4;
Query OK, 1 row affected (0.00 sec)
mysql> select t1.*,t2.* from t1 left join t2 using(id) union all select t1.*,t2.* from t1 right join t2 using(id);
+------+---------+------+---------+
| id   | game_id | id   | game_id |
+------+---------+------+---------+
|    1 |       1 |    1 |       1 | 
|    2 |       2 |    2 |       2 | 
|    3 |       3 |    3 |       6 | 
|    5 |       6 | NULL |    NULL | 
|    6 |       8 |    6 |       4 | 
|    1 |       1 |    1 |       1 | 
|    2 |       2 |    2 |       2 | 
|    3 |       3 |    3 |       6 | 
| NULL |    NULL |    4 |       8 | 
|    6 |       8 |    6 |       4 | 
+------+---------+------+---------+
10 rows in set (0.00 sec)

mysql>