MySQL一些复杂的SQL语句(查询和删除重复行)

MySQL一些复杂的SQL语句(查询和删除重复行)
1。发现重复行
SELECT * FROM blog_user_relation在哪里(a.account_instance_id,a.follow_account_instance_id)
在(选择account_instance_id,follow_account_instance_id从blog_user_relation组account_instance_id,follow_account_instance_id具有
计数(*)> 1)
2。删除重复行(保持一行)

因为MySQL的删除,如果删除表中的位置有一个,并且在里面有这个表,它就不会被删除。
创建一个临时表。
创建表blog_user_relation_temp作为

SELECT * FROM blog_user_relation在哪里
(a.account_instance_id,a.follow_account_instance_id)
在(选择account_instance_id,通过account_instance_id,follow_account_instance_id具有计数从blog_user_relation组follow_account_instance_id(*)> 1)。

relation_id
没有(选择min(relation_id)从blog_user_relation组account_instance_id,follow_account_instance_id有))))

删除数据
删除从` blog_user_relation ` relation_id在哪里(选择relation_id从blog_user_relation_temp);

删除临时表
blog_user_relation_temp表;

tag:查询删除语句电脑软件mysql

相关内容