Created
May 11, 2022 16:25
-
-
Save Osein/106d8396232b0cdc96bdc182a437bf6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE FROM messages | |
WHERE primary_key IN ( | |
SELECT msg.primary_key FROM messages AS msg | |
INNER JOIN ( | |
SELECT MAX(primary_key) AS biggest_primary_key, message_id | |
FROM messages | |
GROUP BY message_id | |
HAVING COUNT(message_id) > 1 | |
) AS dup | |
WHERE msg.message_id = dup.message_id AND msg.primary_key < dup.biggest_primary_key | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment