Distinct

简介: SQL 去重

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'

目录
相关文章
|
17天前
|
SQL 数据库
SQL 查询优化指南:SELECT、SELECT DISTINCT、WHERE 和 ORDER BY
SQL的SELECT语句用于从数据库中选择数据。SELECT语句的基本语法如下:
61 1
|
12月前
ORDER BY子句
ORDER BY子句
37 0
|
Oracle 关系型数据库 MySQL
Mysql数据库,子查询,union,limit篇
参数 expression1, expression2, ... expression_n: 要检索的列。 tables: 要检索的数据表。 WHERE conditions: 可选, 检索条件。 DISTINCT: 可选,删除结果集中重复的数据。默认情况下 UNION 操作符已经删除了重复数据,所以 DISTINCT修饰符对结果没啥影响。 ALL: 可选,返回所有结果集,包含重复数据。 案例:查询工作岗位为MANAGER或者SALESMAN的员工信息(使用union)
119 0
|
存储 .NET C#
C# LINQ 详解 From Where Select Group Into OrderBy Let Join
目录 1. 概述 2. from子句 3. where子句 4. select子句 5. group子句 6. into子句 7. 排序子句 8. let子句 9. join子句 10. 小结 1. 概述     LINQ的全称是Language Integrated Query,中文译成“语言集成查询”。
1995 0
count去重和distinct去重
count去重和distinct去重
6705 0
|
存储 关系型数据库 MySQL
使用filesort来满足ORDER BY (Use of filesort to Satisfy ORDER BY )
filesort ORDER BY (Use of filesort to Satisfy ORDER BY ) MySQL
134 0
|
SQL 索引
SQL去重是用DISTINCT好,还是GROUP BY好?
SQL去重是用DISTINCT好,还是GROUP BY好?
SQL去重是用DISTINCT好,还是GROUP BY好?
|
SQL 关系型数据库 MySQL
select、distinct、limit使用
select、distinct、limit使用
230 0
select、distinct、limit使用