我有一个 MySql 表 (pin_codes)。 起初我想从这个表中恰好选择 200 行并导出它们,然后我想删除这 200 行。
如果这个表的 ID 是连续的,我可以这样做:
SELECT * FROM pin_codes WHERE id<200 and id>1;
DELETE FROM pin_codes WHERE id<200 and id>1;
但是ID是这样的:
52138
52139
52141
52142
52144
52147
52148
52157
52158
...
我该怎么做?
最佳答案
Select * from pin_codes order by id limit 200
将根据 id 给你前 200 行,然后你可以删除这 200 行
Delete from pin-codes order by id limit 200
删除前200行
此外,最好使用列名而不是 *(查询优化)
关于mysql - 从 MySql 表中选择并删除 x 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20592333/