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
Table of contents 1. What is an Operating System ...
<br />In text design, we usually focus on th...
Table of contents 1. What is a transaction? 2. Th...
Install jdk: Oracle official download https://www...
This article example shares the specific code of ...
Table of contents Preface Basic Concepts of Argum...
Preface During the development process, we someti...
Preface Because computer numbers are floating poi...
introduce Monitors the health of HTTP servers in ...
Table of contents <template> <ul class=&...
This article example shares the specific code of ...
Table of contents 1. Teleport 1.1 Introduction to...
@vue+echarts realizes the flow effect of China ma...
The mysql connection must first be initialized th...
1. Implementation principle of scrolling The scro...