sql UNION 和UNION ALL 数据连接查询

UNION 和UNION ALL 数据连接查询

UNION 和UNION ALL 都表示将2个数据集拼接(说白了就是将后面查询的结果拼接到前面查询结果的尾部),但union是去掉重复的和distinct一样union all 是不去重的。

PS:2个查询结果集的字段名称和每个字段的类型要保持一致 不要一个int类型一个varchar类型

select `Id`,`Name` from  Student union select `Id`,CourseName `Name` from  Course 

select `Id`,`Name` from  Student union all select `Id`,CourseName `Name` from  Course 

 

posted @ 2021-05-23 17:38  YorkQi  阅读(135)  评论(0编辑  收藏  举报