Finding duplicate values in a SQL table

后端 未结 30 4616
南旧
南旧 2020-11-21 13:18

It\'s easy to find duplicates with one field:

SELECT name, COUNT(email) 
FROM users
GROUP BY email
HAVING COUNT(email) > 1

So if we have

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-21 13:55

     select emp.ename, emp.empno, dept.loc 
              from emp
     inner join dept 
              on dept.deptno=emp.deptno
     inner join
        (select ename, count(*) from
        emp
        group by ename, deptno
        having count(*) > 1)
     t on emp.ename=t.ename order by emp.ename
    /
    

提交回复
热议问题