1 union all
union all表示不剔除重复记录,
例如:
select device_id, gender, age, gpa from user_profile where university = '山东大学'
union all
select device_id, gender, age, gpa from user_profile where gender = 'male';
2 union
union表示剔除重复记录,
例如:
select device_id, gender, age, gpa from user_profile where university = '山东大学'
union
select device_id, gender, age, gpa from user_profile where gender = 'male';
上述语句查找学校是山东大学或性别为男的记录,相当于
select device_id, gender, age, gpa from user_profile where university = '山东大学' or gender = 'male';
本文介绍了SQL中Union与Union All的区别,Union用于合并两个查询结果集并自动去除重复记录,而Union All则保留所有记录包括重复项。通过具体示例展示了如何使用这两种方法来组合数据。
3万+

被折叠的 条评论
为什么被折叠?



