方法1 delete YourTable where [id] not in ( select max([id]) from YourTable group by (name + value))方法2 delete a from 表 a left join( select id=min(id) from 表 group by name,value )b on a.id=b.id where b.id is null
delete from tt a where exists(select 1 from tt where a.name=name and a.id<>id)
delete YourTable where name = (Select name From YourTable group by name having Count(name)>1)
试下: DELETE from `表名` where `name` in (SELECT temp.`name` FROM (select cnd.`name` from `表名` cnd GROUP BY cnd.`name` HAVING COUNT(cnd.`name`)>1) temp)
delete from tablename where name in (select name from tablename group by name having count(name)>1)
DELETE a.* FROM ttg a INNER JOIN ttg b ON a.name=b.`name` AND a.id<>b.id 在NAME、ID上建立索引
mysql> create temporary table tmp_wrap select * from users_groups group by uid having count(1) >= 1; mysql> truncate table users_groups; mysql> insert into users_groups select * from tmp_wrap; mysql> select * from users_groups; mysql> drop table tmp_wrap; 这样是可以的……只是会留一条记录……
delete YourTable
where [id] not in (
select max([id]) from YourTable
group by (name + value))方法2
delete a
from 表 a left join(
select id=min(id) from 表 group by name,value
)b on a.id=b.id
where b.id is null
DELETE
from `表名`
where `name` in
(SELECT temp.`name`
FROM
(select cnd.`name`
from `表名` cnd
GROUP BY cnd.`name`
HAVING COUNT(cnd.`name`)>1) temp)
a.name=b.`name` AND a.id<>b.id
在NAME、ID上建立索引
mysql> truncate table users_groups;
mysql> insert into users_groups select * from tmp_wrap;
mysql> select * from users_groups;
mysql> drop table tmp_wrap;
这样是可以的……只是会留一条记录……