mysql 中去重distinct总结
distinct总结:
1、distinct是根据字段去除重复的数据。
2、distinct只可以出现在查询字段的最前面。
3、distinct是对后面所有的字段进行组合去重。
根据如下员工表信息,我们对distinct关键字进行总结:

员工信息
1)查询去除重复后的工作岗位;
select ename ,distinct job from emp;

结果报错,主要是应为distinct只可以出现在查询字段的最前面,应为ename有14个,job在去除重复后只有5个,14跟5组合不起来,所有报错。
2)查询不同部门,不同工作岗位的信息,并且去除重复记录。
select distinct deptno,job from emp;

可以看出distinct出现在字段的最前面,是对后面所有字段组合起来去除重复记录的。
3)distinct还可以和分组函数一起使用
查询出工作岗位的总数:select count(distinct(job)) from emp;

工作岗位总数
相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36