56,678
社区成员
发帖
与我相关
我的任务
分享
create table table_name
as
select min(id),b from a group by b;
delete t1 from a t1 where id not in (select min(a.id) from a where a.b=t1.b);
mysql> select * from t_fengchujun;
+------+------+
| id | b |
+------+------+
| 1 | 5 |
| 2 | 6 |
| 3 | 7 |
| 4 | 5 |
| 5 | 7 |
+------+------+
5 rows in set (0.00 sec)
mysql>
mysql> delete t1
-> from t_fengchujun t1,t_fengchujun t2
-> where t1.b=t2.b and t1.id>t2.id;
Query OK, 2 rows affected (0.08 sec)
mysql> select * from t_fengchujun;
+------+------+
| id | b |
+------+------+
| 1 | 5 |
| 2 | 6 |
| 3 | 7 |
+------+------+
3 rows in set (0.00 sec)
mysql>
delete from a t1
where exists
(select 1 from a where a.b=t1.b and a.id<t1.id)
delete a
from A t1,A t2
where t1.b=t2.b and t1.id>t2.id