数据库: show数据表: tbl_vod字段: d_name查找字段 d_name 中重复的数据
select d_name,count(d_name) from tbl_vod group by d_name having count(d_name)>1
谢谢你,这个语句可以查出来某个数据重复的次数,,我想删除里面的重复保留一个要怎么写呢或让他全部显示我手工删除 ,现在查询出来只能显示某个数据的重复次数 没办法选择删除
//去除重复的数据 如果是重复的只显示1个select distinct d_name from tbl_vod--下面是查出重复的记录select d_name from tbl_vodminusselect distinct d_name from tbl_vod
我是想把重复的彻的删除掉呀
有主键字段吗
d_id 这个是主键
delete from tbl_vod where d_id in (select d_id from tbl_vodminusselect max(d_id) from tbl_vod group by d_name)这样应该可以了
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select max(d_id) from tbl_vod group by d_name)' at line 1d_id是不重复的
delete from tbl_vod where d_id not in (select max(d_id) from tbl_vod group by d_name)原来mysql不支持minus数据不多的话 用这句意思是先选出不重复d_name对应的d_id 然后删除d_id不在这些记录里的数据
#1093 - You can't specify target table 'tbl_vod' for update in FROM clause有5万多数据 有几千条重复吧
delect tbl_vod from tbl_vod a,(select max(d_id) from tbl_vod group by d_name) bwhere a.d_id<b.d_id and a.d_name=b.d_name