Finding duplicate values in MySQL

前端 未结 25 2645
执笔经年
执笔经年 2020-11-22 04:04

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 duplic

25条回答
  •  我在风中等你
    2020-11-22 04:29

    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.

提交回复
热议问题