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 throws:
#1093 – You can’t specify target table ‘customers_cards’ for update in FROM clause
I guess I need to use join
as a workaround, but honestly, I cannot rewrite the same logic with join. Any idea how can I write the query above with join
?
2
Answers
The join should be similar to what you would use to select rows in one table but not in another
Here’s an alternative method:
Delete any row
c1
that belongs to ‘ezpay’, provided another rowc2
exists with the samenumber_card
and a lesserid
.