SQL 刪除重復行,只保留一條記錄
刪除表中多余的重復記錄,重復記錄是根據單個字段(id)來判斷,只留有rowid最小的記錄
//刪除用戶根據用戶名,並且不包括最小ID delete from users where username in( //根據用戶名稱排序,大於1 select username from users groupby username having count(username)>1 )and Id not in( --根據用戶名排序,獲取最小ID select min(Id) from users groupby username having count(username)>1 )