MySql删除class_id最小的条目

MySql删除class_id最小的条目

一个表(表明test_table)的数据如下,有两个字段id和class_id:


1. MySQL中删除class_id为最小的数据:

DELETE FROM test_table
WHERE class_id IN (
    SELECT mid FROM (SELECT MIN(class_id) mid FROM test_table t1) t2
);


2. 保留class_id为最小的删除其它数据:

DELETE FROM test_table
WHERE class_id NOT IN (
    SELECT mid FROM (SELECT MIN(class_id) mid FROM test_table t1) t2
);


6

相关文章