日期:2014-05-16  浏览次数:20688 次

mysql去除一张表中的重复数据问题,求高手!
我的
sql语句是:delete from ec_core_userthread as m,(select ID from ec_core_userthread group by user_code having count(*)>1) as n where m.user_code = n.user_code and m.id > n.id
但是执行是会说语法错误,求高手帮忙看看!

需求是:我的ec_core_userthread表中存在user_code重复的数据,我想把重复的数据去除了。。

------解决方案--------------------
create table aaaa as select max(c.pkid) id from tb_contact c group by c.UserID;
delete from tb_contact where pkid not in (select id from aaaa); 
drop table aaaa;

------解决方案--------------------
delete m from ec_core_userthread as m left join (select ID from ec_core_userthread group by user_code) as n on m.ID = n.ID where n.ID is null