我想在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 |
---------------------------------------
有关如何做到这一点的任何想法?
答案 0 :(得分:3)
尝试GROUP_CONCAT
SELECT GROUP_CONCAT(id), column_A, column_B
FROM mytable
GROUP BY columnA, columnB
HAVING COUNT(id) > 1
答案 1 :(得分:2)
select group_concat(id) as duplicate_ids,
columna,
columnb
from your_table
group by columna, columnb
having count(id) > 1
答案 2 :(得分:2)
SELECT
GROUP_CONCAT(id) as ids,
column_a,
column_b
FROM table
GROUP BY column_a, column_b
HAVING COUNT(id) > 1
答案 3 :(得分:1)
尝试group_contact ()
功能,
select group_concat(id) duplicate_ids ,column_a, column_b
from <table>
group by column_a, column_b