刪除數(shù)據(jù)庫中的重復記錄
          SqlServer:
          delete from team where id in (select min(id) from team group by [name] having count(id) > 1)
          MySql:

          Error Code : 1064
          You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[name] having count(id) > 1)' at line 1
          (0 ms taken)

          so:

          create temporary table tmp_wrap select * from users_groups group by uid having count(1>= 1;

          truncate table users_groups;

          insert into users_groups select * from tmp_wrap;

          drop table tmp_wrap;

          OR:
          delete team as a from team as a,(select min(id) as id,`name` from team group by `name` having count(id) > 1as b where a.id=b.id and a.`name`=b.`name`


          posted on 2010-07-09 20:57 Ying-er 閱讀(2099) 評論(0)  編輯  收藏 所屬分類: MySql

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 雅安市| 临江市| 黔西| 布拖县| 原平市| 乌拉特后旗| 芮城县| 陆丰市| 调兵山市| 满城县| 松溪县| 景宁| 祁阳县| 蓬溪县| 扶余县| 海淀区| 湖南省| 老河口市| 东兴市| 同仁县| 古浪县| 吴忠市| 安宁市| 平凉市| 元谋县| 宜良县| 武宁县| 南京市| 台前县| 巢湖市| 锡林郭勒盟| 浮梁县| 长武县| 长寿区| 咸宁市| 曲松县| 松桃| 凤城市| 遂川县| 怀化市| 尼勒克县|