MySql删除重复的记录

09. May 2020 DataBase 0
DELETE
FROM
word_relation_books
WHERE
(book_id, word_id) IN (SELECT a.book_id,a.word_id from ( SELECT book_id, word_id FROM word_relation_books GROUP BY book_id, word_id HAVING count(* )> 1 ) a)
AND id NOT IN (
SELECT
b.id
FROM
( SELECT min( id ) AS id FROM word_relation_books GROUP BY book_id, word_id HAVING count(* )> 1 ) b)

Leave a Reply

Your email address will not be published. Required fields are marked *