Skip to content

Instantly share code, notes, and snippets.

@k4zuki02h4t4
Created August 23, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4zuki02h4t4/61a30ce624adf2d81dc8cb615463c8df to your computer and use it in GitHub Desktop.
Save k4zuki02h4t4/61a30ce624adf2d81dc8cb615463c8df to your computer and use it in GitHub Desktop.
重複するデータを削除する SQL。出典 https://chaika.hatenablog.com/entry/2019/02/21/120000
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