I'm trying to execute this query which finds some elements with duplicate message_id
, changes the message_id
of all but the last element (largest id)...
UPDATE messages
SET message_id = $1, parent_id= $2
WHERE message_id = $2
AND id NOT IN (SELECT MAX(id) FROM messages WHERE message_id= $2
But it keeps giving me this error:
(1093, "You can't specify target table 'messages' for update in FROM clause")
How do I get around this??