首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql去除一张表中的重复数据有关问题,求高手

2012-06-08 
mysql去除一张表中的重复数据问题,求高手!我的sql语句是:delete from ec_core_userthread as m,(select ID

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

热点排行