衫裤跑路 2009-03-27 04:22 采纳率: 50%
浏览 169
已采纳

在 MySQL 中查找重复值

I have a table with a varchar column, and I would like to find all the records that have duplicate values in this column. What is the best query I can use to find the duplicates?

转载于:https://stackoverflow.com/questions/688549/finding-duplicate-values-in-mysql

  • 写回答

21条回答 默认 最新

  • MAO-EYE 2009-03-27 04:24
    关注

    Do a SELECT with a GROUP BY clause. Let's say name is the column you want to find duplicates in:

    SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1;
    

    This will return a result with the name value in the first column, and a count of how many times that value appears in the second.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(20条)

报告相同问题?

悬赏问题

  • ¥40 图书信息管理系统程序编写
  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题