mySQL查询查找重复行

编程入门 行业动态 更新时间:2024-10-27 10:18:09
本文介绍了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查询查找重复行

本文发布于:2023-10-27 02:43:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532070.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!