I have the following query:
delete from customers_cards where id not in ( select min(id) from customers_cards group by number_card ) and belongs_to = "ezpay"
It reports an error:
#1093 - In the FROM clause, the target table 'customers_cards' cannot be specified for the update
I guess I need to use join
as a workaround, but honestly I can't rewrite the same logic using join
. Is there a way to write the above query using join
?
Here is another way:
Delete any row
c1
that belongs to 'ezpay', provided there is another rowc2
with the samenumber_card
and a smallerid
.This join should be similar to how you would select rows in one table but not the other.