今天看到一个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博客 ” ,链接:http://blog.itpub.net/8111049/viewspace-621957/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8111049/viewspace-621957/