1. Find duplicate rows SELECT * FROM blog_user_relation a WHERE (a.account_instance_id,a.follow_account_instance_id) IN (SELECT account_instance_id,follow_account_instance_id FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*) > 1) 2. Delete duplicate rows (keep one) PS: Because of MySQL's delete, if the where condition of the deleted table contains in, and this table also exists in in, then it cannot be deleted. /*Create a temporary table*/ CREATE TABLE blog_user_relation_temp AS ( SELECT * FROM blog_user_relation a WHERE (a.account_instance_id,a.follow_account_instance_id) IN ( SELECT account_instance_id,follow_account_instance_id FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*) > 1) AND relation_id NOT IN (SELECT MIN(relation_id) FROM blog_user_relation GROUP BY account_instance_id, follow_account_instance_id HAVING COUNT(*)>1)); /*delete data*/ DELETE FROM `blog_user_relation` WHERE relation_id IN (SELECT relation_id FROM blog_user_relation_temp); /*Delete temporary table*/ DROP TABLE blog_user_relation_temp; You may also be interested in:
|
<<: Implementing a puzzle game with js
>>: Listen directive example analysis in nginx
Install vsftpd $ sudo apt-get install vsftpd -y S...
Table of contents 1. Introduction 2. Simple epoll...
What is Docker-Compose The Compose project origin...
How to use iframe: Copy code The code is as follo...
Table of contents 1. Introduction to Portainer 2....
Table of contents Proxy forwarding rules The firs...
Original URL: http://segmentfault.com/blog/ciaocc/...
This time we use HTML+CSS layout to make a prelim...
1. Software Introduction VirtualBox VirtualBox is...
There is a simple CSS method to realize the pop-u...
Setting the font for the entire site has always b...
1. Install the virtual machine hyper-v that comes...
Today, I will record how to install MySQL 8.0.18 ...
We usually use float layout to solve the compatib...
MySQL is a relational database management system ...