2012-08-07 93 views
0

我想在MySQL數據庫中提取重複記錄。在MySQL中查找帶有重複記錄的ID

---------------------------- 
| 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  | 
--------------------------------------- 

任何思考如何可以做到這一點?

回答

2
select group_concat(id) as duplicate_ids, 
     columna, 
     columnb 
from your_table 
group by columna, columnb 
having count(id) > 1 
1

嘗試group_contact()功能,

select group_concat(id) duplicate_ids ,column_a, column_b 
from <table> 
group by column_a, column_b 
3

嘗試GROUP_CONCAT

SELECT GROUP_CONCAT(id), column_A, column_B 
FROM  mytable 
GROUP BY columnA, columnB 
HAVING COUNT(id) > 1 
2
SELECT 
    GROUP_CONCAT(id) as ids, 
    column_a, 
    column_b 
FROM table 
GROUP BY column_a, column_b 
HAVING COUNT(id) > 1