SQL中删除同一字段中重复的值_MySQL
来源:懂视网
责编:小采
时间:2020-11-09 20:10:55
SQL中删除同一字段中重复的值_MySQL
SQL中删除同一字段中重复的值_MySQL: /////////////////////目地:ZDJZ_DIS中 name字段有重复的值,删除重复的值 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NAME from ZDJZ_DIS group by NAME having count(NAME) >1); 上面的做法会删除掉所有的相同的
导读SQL中删除同一字段中重复的值_MySQL: /////////////////////目地:ZDJZ_DIS中 name字段有重复的值,删除重复的值 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NAME from ZDJZ_DIS group by NAME having count(NAME) >1); 上面的做法会删除掉所有的相同的
/////////////////////目地: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);
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
SQL中删除同一字段中重复的值_MySQL
SQL中删除同一字段中重复的值_MySQL: /////////////////////目地:ZDJZ_DIS中 name字段有重复的值,删除重复的值 DELETE * FROM ZDJZ_DIS WHERE NAME IN (select NAME from ZDJZ_DIS group by NAME having count(NAME) >1); 上面的做法会删除掉所有的相同的