sql 去重关键字 distinct

单列去重:

mysql:

drop table test;
create table test(id int(4));
insert into test values(1),(2),(3),(4),(1),(2);
select count(distinct id) from test;
oracle:
drop table test;
create table test(id number(4));
insert all
into test values(1)
into test values(2)
into test values(3)
into test values(4)
into test values(1)
into test values(2)
select * from dual;
select count(distinct id) from test;


多列去重:

select deptno, job from emp; -- 结果有重复的

select distinct deptno, job from emp; -- deptno 和 job 两个字段的值都相同,那么去重

原文地址:https://www.cnblogs.com/Mike_Chang/p/9311571.html