php技术博客
让天下没有搞不定的bug~

mysql删除字段重复的数据

mysql删除字段重复的数据,经过搜索刚开始是这样做的:
[warning]delete from v_togo
where tel in (select tel from v_togo group by tel having count(tel) > 1)
and togoid not in (select min(togoid) from v_togo group by tel having count(tel )>1)[/warning]
结果mysql报错
[author]you can’t specify target table ‘v_togo’ for update in from clause[/author]
然后我是这样解决的,分三个步骤:
[author]1、create table tmp as select max(togoid) as toid from v_togo group by tel; 先把要处理的字段存储到临时表
2、delete from v_togo where togoid not in (select toid from tmp); 根据临时表进行筛选
3、drop table tmp;删除临时表[/author]
这样就ok了。
 

赞(0)
未经允许不得转载:PHP技术博客 » mysql删除字段重复的数据