Mysql union联合查询
super
2021-04-15 19:10
3057
1.UNION 用于合并两个或多个 SELECT 语句的结果集,并消去表中任何重复行。
2.UNION 内部的 SELECT 语句必须拥有相同数量的列,列也必须拥有相似的数据类型,每条 SELECT 语句中的列的顺序必须相同.
3.UNION ALL允许有重复的行
SELECT column_name FROM table1
UNION
SELECT column_name FROM table2
UNION ALL不消除重复行
SELECT column_name FROM table1
UNION ALL
SELECT column_name FROM table2
重复
(select * from talbe order by id) UNION ALL (select * from talbe order by id);
不重复
(select * from talbe order by id) UNION (select * from talbe order by id);
0 条讨论