本文介绍了mySQL查询查找重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Exmaple:
[empid date bookid] ---------- 1 5/6/2004 8 2 5/6/2004 8 1 5/7/2004 8 1 5/8/2004 6 3 5/8/2004 8 2 5/8/2004 7在这个表中,我需要将empid 1作为输出。因为它已经有多个bookid 8。
In this table,I need to get empid 1 as output..since it has bookid 8 more than once..
提前感谢
推荐答案您可以使用:
SELECT DISTINCT id FROM table GROUP BY empid, bookid HAVING COUNT(*) > 1但它会给你重复。例如,如果您有1-8,1-8,1-9,1-9,您将获得1,1作为输出,因为empid 1对于两个不同的bookid值具有重复的bookid。您将需要使用 SELECT DISTINCT 过滤掉重复的empid。
But it will give you duplicates. If, for example, you have 1-8,1-8,1-9,1-9 you will get 1,1 as output because empid 1 has duplicate bookid's for two distinct bookid values. You will need to use SELECT DISTINCT to filter out the duplicate empid.
更多推荐
mySQL查询查找重复行
发布评论