摘要:重複資料查詢
這篇有兩個狀況
- 列出重複的項目,一種列一筆
- 列出重複的項目,有幾項列幾項
ID | Content |
1 | AAA |
2 | AAA |
3 | BBB |
4 | CCC |
5 | CCC |
在1的情況下會出現
ID | Content |
1 | AAA |
4 | CCC |
語法:
SELECT * FROM Table Group by Content Having Count(*) > 1
在2的情況下會出現
ID | Content |
1 | AAA |
2 | AAA |
4 | CCC |
5 | CCC |
語法:
SELECT *
FROM Table
WHERE Content IN (SELECT Content FROM Table Group by Contnet HAVING COUNT(*) > 1)