I would like to mark rows as deleted when there are duplicate stock codes. This is my current query:
UPDATE stock s1
SET s1.deleted_at = now()
WHERE s1.product_id != (
SELECT MIN(s2.product_id)
FROM stock s2
WHERE s2.stock_code = s1.stock_code
)
Error returned is:
SQL Error (1093): You can't specify target table 's' for update in FROM clause
I have tried wrapping it within another sub query but unable to get it working