1.查找重复的行

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)

PS:因为mysql的delete,如果被删的表的where条件里有in,且in里面也有此表,那就删除不了。

/*创建个临时表*/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 FROM `blog_user_relation` WHERE relation_id IN (SELECT relation_id FROM blog_user_relation_temp);/*删除临时表*/DROP TABLE blog_user_relation_temp;

更多相关文章

  1. Android(安卓)-- Android(安卓)JUint 与 Sqlite
  2. android 当系统存在多个Launcher时,如何设置开机自动进入默认的La
  3. Android(安卓)SQLiteDatabase的使用
  4. android一种较为复杂的布局参考(xml文件)
  5. android 通话记录次数
  6. Android(安卓)SQLiteDatabase的使用
  7. 关于Android/java的复杂对象的深拷贝和浅拷贝
  8. android实现关键字搜索功能
  9. 我的android 第14天 - 使用SQLiteDatabase操作SQLite数据库

随机推荐

  1. 在线求助.Select语句包含ERP单据内表头与
  2. SQL表的简单操作
  3. Sailsjs Mysql ORM在同一个表字段上进行
  4. sql将数据为0的转换为空
  5. C#的委托事件在winform窗体中实现传值备
  6. Java向MySQL数据库插入时间类型Date数据
  7. SQL优化--使用 EXISTS 代替 IN 和 inner
  8. 如何在SQLite中获取最后的插入Id ?
  9. LinuxRPM安装MySQL5.0.16
  10. sqlDataRead dr = db.reDr(sqlStr); 出错