-
-
Save k4zuki02h4t4/61a30ce624adf2d81dc8cb615463c8df to your computer and use it in GitHub Desktop.
重複するデータを削除する SQL。出典 https://chaika.hatenablog.com/entry/2019/02/21/120000
This file contains hidden or 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 | |
table_a | |
WHERE id NOT IN ( | |
SELECT | |
id | |
FROM( | |
SELECT | |
* | |
FROM | |
table_a AS t1 | |
WHERE 1 = ( | |
SELECT | |
COUNT(*) | |
FROM | |
table_a AS t2 | |
WHERE | |
t1.shop_id = t2.shop_id | |
AND t1.date = t2.date | |
AND t1.id >= t2.id | |
) | |
) AS tmp | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment