Question

I am getting the following error

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

while executing the following query:

 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);

in MYSQl database

The select query is working fine. What can possibly be wrong?

Was it helpful?

Solution 2

I have solve this problem. I had to use an alias name for the inner query. Don't know why but I have made the query run!! here is my updated query.

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); 

OTHER TIPS

Instead of Delete from tableName just write Delete tableName

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top