保留id最小记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
DELETE FROM table WHERE id NOT IN ( SELECT dt.minno FROM ( SELECT MIN(id) AS minno FROM table GROUP BY id ) dt ) |
保留id最大记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
DELETE FROM table WHERE id NOT IN ( SELECT dt.minno FROM ( SELECT MAX(id) AS minno FROM table GROUP BY id ) dt ) |
多字段删除,保留id最小记录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
DELETE FROM table WHERE id NOT IN ( SELECT dt.minno FROM ( SELECT MIN(id) AS minno FROM table GROUP BY id,name ) dt ) |
近期评论