如何从id重复的数据库mysql中获取重复条目

时间:2016-04-21 01:42:41

标签: php mysql

我希望从mysql返回重复的ID 这是我的查询

>     SELECT COUNT(title) AS duplicate_Count , title , id
>     FROM lyric
>     GROUP BY title
>     HAVING COUNT(title) > 1

结果如下:

duplicate_Count  title id
2     text     121
3     text_2    233

但我想要这个结果:

duplicate_Count  title id
2     text     121 , 122
3     text_2    233 ,260 ,56

任何帮助,请

1 个答案:

答案 0 :(得分:2)

id更改为GROUP_CONCAT(id)

SELECT COUNT(title) AS duplicate_Count , title , GROUP_CONCAT(id)
FROM lyric
GROUP BY title
HAVING COUNT(title) > 1

Example