數據清理——刪除多個字段重復的記錄
阿新 • • 發佈:2018-10-09
刪除 alt abc mage 字段 sel png inf max
數據庫內容,隨機編了一些數據,其中認為兩個字段Name、Address1一致為重復記錄,保留其中一條
- 刪除兩個字段Name、Address1一致重 復的記錄,保留一條:
- 找出,( 如果沒有第三行,會有什麽問題呢?可將示例數據中 ID 為4的行,Name字段改為Tom測試一下)
1 select * from tableabc 2 where Name in( select Name from tableabc group by Name, Address1 having count(Name) > 1) 3 and Address1 in( select Address1 from tableabc group by Name, Address1 having count(Address1) > 1)
-
- 刪除
1 select * from tableabc 2 where Name in( select Name from tableabc group by Name, Address1 having count(Name) > 1) 3 and Address1 in( select Address1 from tableabc group by Name, Address1 having count(Address1) > 1) 4 and ID not in(select max(ID) from tableabc group by Name,Address1 having count(Name) > 1 )
數據清理——刪除多個字段重復的記錄