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
);


5

相關文章

25选5走势图