删除重复行 error 1093

删除重复行和error 1093


解决1:直接删除(拥有自动增长的cust_id列)

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BYcust_name)as a);

 

解决2:删除重建

create table tmp   (select a.* from customers a,

     (select min(cust_id) as cust_id from `customers` group by cust_name)  b where a.cust_id=b.cust_id);

create table tmp2 select min(cust_id) as cust_id,

cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country,cust_contact,cust_email

from`customers` GROUP BY cust_name;

create table tmp1 select distinct * from customers_copy;    //没有自动增长id列,采用这种方法

 

drop table customers;

rename table tmp to customers;

 



我在创建过程中出现了一个如下报错:

1093错误:You can'tspecify target table 'perf_linux_t' for update in FROM clause 

解决:将子查询变为孙子查询,再嵌套一个查询,一定要定义别名

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BY cust_name) as a); 

 

附:

//查看表中的重复行信息

select cust_name from (SELECT cust_name,count(*) FROM `customers` GROUP BY cust_name having count(*)>1);

 

//若没有自动增长的id列,可以添加

ALTER TABLE `perf_linux_t` ADD COLUMN `auto_id`INT NOT NULL AUTO_INCREMENT primary key;

 



如果大家还有更好的方法,望高手指点。

我在创建过程中出现了一个如下报错:

1093错误:You can'tspecify target table 'perf_linux_t' for update in FROM clause 

解决:将子查询变为孙子查询,再嵌套一个查询,一定要定义别名

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BY cust_name) as a); 

 

附:

//查看表中的重复行信息

select cust_name from (SELECT cust_name,count(*) FROM `customers` GROUP BY cust_name having count(*)>1);

 

//若没有自动增长的id列,可以添加

ALTER TABLE `perf_linux_t` ADD COLUMN `auto_id`INT NOT NULL AUTO_INCREMENT primary key;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值