问题描述
我正在尝试运行 SQL 查询以删除表中 ID 为 163 到 265 的行
I am trying to run a SQL query to delete rows with id's 163 to 265 in a table
我尝试这样做是为了删除更少的行
I tried this to delete less number of rows
DELETE FROM `table` WHERE id IN (264, 265)
但是当一次删除100行时,是否有类似上述方法的查询我也在尝试使用这种查询,但未能执行
But when it comes to delete 100's of rows at a time, Is there any query similar to above methodI am also trying to use this kind of query but failed to execute it
DELETE FROM `table` WHERE id IN (SELECT * FROM table WHERE id = )
请告诉我执行上述操作的查询...
Please tell me the query to do the above action...
推荐答案
如果需要基于列表删除,可以使用IN
:
If you need to delete based on a list, you can use IN
:
DELETE FROM your_table
WHERE id IN (value1, value2, ...);
如果需要根据查询结果进行删除,也可以使用IN
:
If you need to delete based on the result of a query, you can also use IN
:
DELETE FROM your_table
WHERE id IN (select aColumn from ...);
(注意子查询只能返回一列)
(Notice that the subquery must return only one column)
如果您需要根据某个范围的值进行删除,请使用 BETWEEN
或使用不等式:
If you need to delete based on a range of values, either you use BETWEEN
or you use inequalities:
DELETE FROM your_table
WHERE id BETWEEN bottom_value AND top_value;
或
DELETE FROM your_table
WHERE id >= a_value AND id <= another_value;
这篇关于如何在 id = (x to y) 的 SQL 中删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!