Distinct(DA思肾科特)
distinct(去重)用来查询不重复记录的条数,即distinct来返回不重复字段的条数(count(distinct id))(去掉重复的将不重复的显示出来)
语法:Select Distinct 字段名 From 表名
案例1:对一个字段查重,表示选取该字段一列不重复的数据
案例表:Student
StudentNo去重
解答语句:Select Distinct StudentNo from Student
Union
会对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序
SELECT StudentName FROM student where StudentName = '小花'
union
Select StudentName from student where StudentName = '小花1'
Union all
对两个结果集进行并集操作,包括重复行,不会对结果进行排序
SELECT StudentName FROM student where StudentName = '小花'
union all
Select StudentName from student where StudentName = '小花1'