I am trying to do the following query:
DELETE FROM main_history WHERE id NOT IN (
SELECT max(id) FROM main_history GROUP BY instance_id, xpath, new_value
)
However, I get the following error:
You can't specify target table 'main_history' for update in FROM clause
Is there a way to do this directly in mysql in a single query? I'm currently creating a tmp table like so:
INSERT INTO main_history_new (
SELECT id, instance_id, territory_id, xpath, field, old_value, new_value, max(date)
FROM main_history
GROUP BY instance_id, xpath, new_value
)