/////////////////////目地:ZDJZ_DIS中 name字段有重復的值,刪除重復的值 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NAME from ZDJZ_DIS group by NAME having count(NAME) >1); 上面的做法會刪除掉所有的相同的值,包括你想要的,只要重復就刪除 DELETE * FROM ZDJZ_DIS WHERE ID in (select min(ID) from ZDJZ_DIS group by NAME having count(NAME)>1); 1有沒有重復的某項值 2如果有的話,選擇ID最小的那個 結合起來 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NAME from ZDJZ_DIS group by NAME having count(NAME) >1) and ID not in (select min(ID) from ZDJZ_DIS group by NAME having count(NAME)>1);