MySQL中的联合查询

联合查询:就是把多个查询语句(两个select)的查询结果放在一起,其有两个关键字union和union all.

示例:两张表student,teacher

            

关键字一:union

union:在进行联合查询后会去掉重复的元素.

select * from student 
union 
select * from teacher 

关键字二:union all

union all:两个结果集只进行简单的合并,包含重复的元素,它的查询速度要比union快的多,因此在确定查询的结果集中不包含重复的数据时优先考虑使用union all.

select * from student 
union all
select * from teacher 

猜你喜欢

转载自blog.csdn.net/weixin_39737132/article/details/89058535