ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 删除重复记录

删除重复记录

原创 Linux操作系统 作者:haoyuanfen 时间:2009-12-08 16:04:43 0 删除 编辑

今天看到一个ebook中一个删除重复记录的不错方法!

Deleting Duplicate Rows
It's occasionally necessary to delete "duplicate" rows from a table. This need probably arises more often on test systems than on production systems. One approach to deleting duplicate rows is to arbitrarily delete all but the one with the lowest ROWID value:


DELETE FROM course
WHERE ROWID NOT IN (
                SELECT MIN(ROWID)
                FROM course
                GROUP BY course_name, period);


The GROUP BY clause in the subquery defines "duplicate" as two rows having the same course name and period. The subquery returns a list of ROWID values in which each value represents the minimum ROWID for a given combination of course name and period. Those rows are retained. The use of NOT IN results in all other rows being deleted.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8111049/viewspace-621957/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-04-02

  • 博文量
    55
  • 访问量
    283764