2014-04-29 39 views
-1

在执行下面的查询我收到以下错误删除查询使用IN子句MYSQL

"Lookup Error - MySQL Database Error: You can't specify target table 'customer_copy' for update in FROM clause"

Delete from customer_copy where code IN 
(select cuc.code from customer_copy cuc 
INNER JOIN customer_copy1 cu ON cuc.code = cu.code 
where cuc.district=cu.district and cuc.city = cu.city and 
cuc.name = cu.name and cuc.country = cu.country and 
cuc.customer_grp1 = cu.customer_grp1 and 
cuc.email = cu.email and cuc.fax = cu.fax and 
cuc.house_number = cu.house_number and 
cuc.name=cu.name and cuc.postal_code = cu.postal_code and 
cuc.region = cu.region and cuc.street = cu.street and 
cuc.tax_juris_code = cu.tax_juris_code and 
cuc.tax_number1 = cu.tax_number1 and 
cuc.tele = cu.tele and cuc.plant_code = cu.plant_code and 
cuc.employee_code = cu.employee_code and 
cuc.sales_district_code = cu.sales_district_code and 
cuc.sales_office_code = cu.sales_office_code and 
cuc.tax_number2 = cu.tax_number2 and 
cuc.tax_number3 = cu.tax_number3 and 
cuc.search_terms_1 = cu.search_terms_1 and 
cuc.search_terms_2 = cu.search_terms_2); 

在MySQL数据库

select查询工作正常。什么可能是错的?

+2

如果您想让某人花时间帮助您,那么您应该将其格式化为可读的内容。 – mawburn

回答

0

我必须解决这个问题。我不得不为内部查询使用别名。不知道为什么,但我已经使查询运行! 这里是我更新的查询。

delete cc.* from customer_copy cc where cc.code IN 
(select code from (select cu.code from customer_copy cu 
INNER JOIN customer_copy1 cuc ON cuc.code = cu.code 
where cuc.district=cu.district and cuc.city = cu.city and 
cuc.name = cu.name and cuc.country = cu.country and 
cuc.customer_grp1 = cu.customer_grp1 and 
cuc.email = cu.email and cuc.fax = cu.fax and 
cuc.house_number = cu.house_number and 
cuc.name=cu.name and cuc.postal_code = cu.postal_code and 
cuc.region = cu.region and cuc.street = cu.street and 
cuc.tax_juris_code = cu.tax_juris_code and 
cuc.tax_number1 = cu.tax_number1 and 
cuc.tele = cu.tele and cuc.plant_code = cu.plant_code and 
cuc.employee_code = cu.employee_code and 
cuc.sales_district_code = cu.sales_district_code and 
cuc.sales_office_code = cu.sales_office_code and 
cuc.tax_number2 = cu.tax_number2 and 
cuc.tax_number3 = cu.tax_number3 and 
cuc.search_terms_1 = cu.search_terms_1 and 
cuc.search_terms_2 = cu.search_terms_2)x); 
2

而不是Delete from tableName只写Delete tableName

+0

谢谢@RezaRahmati。但是,这将删除整个表,我只是想删除一些行 –

+0

@ManthanShah你的where语句应该被添加,我说从你的语句发出'from'。 – RezaRahmati