0

我想提取 MySQL 数据库中的重复记录。

----------------------------
| id | column_a | column_b |
|----|----------|----------| 
| 1  |    a     |    b     |
| 2  |    a     |    c     |
| 3  |    a     |    d     |
| 4  |    a     |    b     |
| 5  |    b     |    e     |
| 6  |    c     |    a     |
| 7  |    c     |    d     |
| 8  |    e     |    a     |
| 9  |    e     |    a     |
----------------------------

我想拉它,以便它显示重复的每一行。就像是 :

------
| id |
|----|
| 1  |
| 4  |
| 8  |
| 9  |
------

或者

---------------------------------------
| duplicate_ids | column_a | column_b |
|---------------|----------|----------| 
|      1,4      |    a     |    b     |
|      8,9      |    e     |    a     |
---------------------------------------

关于如何做到这一点的任何想法?

4

4 回答 4

3

尝试GROUP_CONCAT

SELECT    GROUP_CONCAT(id), column_A, column_B
FROM      mytable
GROUP BY  columnA, columnB
HAVING    COUNT(id) > 1
于 2012-08-07T08:19:16.920 回答
2
SELECT
    GROUP_CONCAT(id) as ids,
    column_a,
    column_b 
FROM table
GROUP BY column_a, column_b 
HAVING COUNT(id) > 1
于 2012-08-07T08:20:24.380 回答
2
select group_concat(id) as duplicate_ids,
       columna, 
       columnb
from your_table
group by columna, columnb
having count(id) > 1
于 2012-08-07T08:17:51.743 回答
1

尝试group_contact ()功能,

select group_concat(id) duplicate_ids ,column_a, column_b
from <table>
group by column_a, column_b
于 2012-08-07T08:19:12.730 回答