mySQL查询查找重复行 [英] mySQL query to find duplicate row

查看:157
本文介绍了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查询查找重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆