Answer the question
In order to leave comments, you need to log in
What is the best way to remove duplicate rows in MySQL?
Good day to all! Guys, I need to remove the next duplicates so as not to kill the entire database..
Exhaust from under "SELECT * FROM [table name];"
--------------+----------+------+---------------------+---------------------+
| id | order | name | name_slug | posturl_slug | description | type | icon | disabled | main | created_at | updated_at |
+----+-------+---------------+---------------+--------------+---------------------------------------------------------------------------------------+-----------+-------------------------------------------+----------+------+---------------------+---------------------+
| 1 | 1 | News | news | news | News enables you to share the latest breaking news content on the web. | news | <i class=material-icons>library_books</i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 2 | 2 | Lists | lists | list | Create most interesting viral lists on your site and share with all your friends. | list | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 3 | 3 | Quizzes | quizzes | quiz | Get start to make great viral quizzes with Quizzes Plugin TODAY! | quiz | <i class=material-icons></i> | 1 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 4 | 4 | Polls | polls | poll | Polls are awesome! Share all questions in your mind! Learn the other people thoughts. | poll | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 5 | 5 | Videos | videos | video | Share post popular, funny videos. | video | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 6 | 0 | Inbox | inbox | inbox | | mailcat | inbox | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 7 | 0 | Sent | sent | sent | | mailcat | envelope-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 8 | 0 | Drafts | drafts | drafts | | mailcat | file-text-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 9 | 0 | Junk | junk | junk | | mailcat | filter | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 10 | 0 | Trash | trash | trash | | mailcat | trash-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 11 | | Advertisement | advertisement | | #B77528 | maillabel | | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 12 | | Other | other | | #B22D5B | maillabel | | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 13 | 1 | News | news | news | News enables you to share the latest breaking news content on the web. | news | <i class=material-icons>library_books</i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 14 | 2 | Lists | lists | list | Create most interesting viral lists on your site and share with all your friends. | list | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 15 | 3 | Quizzes | quizzes | quiz | Get start to make great viral quizzes with Quizzes Plugin TODAY! | quiz | <i class=material-icons></i> | 1 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 16 | 4 | Polls | polls | poll | Polls are awesome! Share all questions in your mind! Learn the other people thoughts. | poll | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 17 | 5 | Videos | videos | video | Share post popular, funny videos. | video | <i class=material-icons></i> | 0 | 1 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 18 | 0 | Inbox | inbox | inbox | | mailcat | inbox | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 19 | 0 | Sent | sent | sent | | mailcat | envelope-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 20 | 0 | Drafts | drafts | drafts | | mailcat | file-text-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 21 | 0 | Junk | junk | junk | | mailcat | filter | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 22 | 0 | Trash | trash | trash | | mailcat | trash-o | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 23 | | Advertisement | advertisement | | #B77528 | maillabel | | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
| 24 | | Other | other | | #B22D5B | maillabel | | 0 | 0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
Answer the question
In order to leave comments, you need to log in
as one of the options you can do this:
DELETE
FROM `tablename`
WHERE `id` NOT IN
(SELECT min(`id`) AS `id`
FROM `tablename`
GROUP BY `name`);
If this is the whole database, then delete it manually through some phpMyAdmin faster, write a question to the toaster.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question