数据库问题
昨天招银电面被问的,如何删除一个没有主键的表中的所有重复数据,只要有重复就一条都不保留。
刚刚在mysql里面试,
create table tmp as SELECT id,name from test GROUP BY id,name HAVING count(*)>1;
SELECT * from test a where EXISTS (select * from tmp b where a.id=b.id and a.name=b.name);
drop table tmp;
这样是可以选出所有重复数据的,可是把select *改为delete为什么就显示错误呢?
刚刚在mysql里面试,
create table tmp as SELECT id,name from test GROUP BY id,name HAVING count(*)>1;
SELECT * from test a where EXISTS (select * from tmp b where a.id=b.id and a.name=b.name);
drop table tmp;
这样是可以选出所有重复数据的,可是把select *改为delete为什么就显示错误呢?