MySQL基础知识
1、union和union all的区别: union和union all都可以将两边的查询结果合并,区别在于union的合并会去掉重复行,并且使用默认的排序规则。而union all返回所有行(包括重复行),且对结果不进行排序。 举例如现在创建2张表: Create table Table1 ( id int not null, name varchar(20) not null ); Create table Table2 ( id int not null, name varchar(20) not null ); 插入数据(数据来自网上): Insert into Table1 values (1,'姚羽'); Insert into Table1 values (2,'边兵兵'); Insert into Table1 values (3,'袁磊'); Insert into Table2 values (1,'姚羽'); Insert into Table2 values (2,'柳春平'); Insert into Table2 values (3,'张永超'); Insert into Table2 values (4,'刘华健'); 执行:select * from Table1 union select * from Table2; 执行:select *