如何删除SQL中的多行,其中id =(x到y)

我试图运行一个SQL查询来删除表中id为163到265的行

我试图删除更less的行数

DELETE FROM `table` WHERE id IN (264, 265) 

但是,当涉及到一次删除100的行,有没有类似于上述方法的查询我也试图使用这种查询,但未能执行它

  DELETE FROM `table` WHERE id IN (SELECT * FROM table WHERE id = ) 

请告诉我做查询做上面的动作…

如果您需要根据列表进行删除,则可以使用IN

 delete from your_table where id in (value1, value2, ...); 

如果您需要根据查询结果删除,也可以使用IN

 delete from your_table where id in (select aColumn from ...); 

(请注意,子查询必须只返回一列)

如果您需要根据一系列值删除,则可以使用BETWEEN或使用不等式:

 delete from your_table where id between bottom_value and top_value; 

要么

 delete from your_table where id >= a_value and id <= another_value; 

您可以使用BETWEEN

 DELETE FROM table where id between 163 and 265 

请尝试这个;

  DELETE FROM `table` WHERE id >=163 and id<= 265 
 Delete Id from table where Id in (select id from table) 
 CREATE PROC [dbo].[sp_DELETE_MULTI_ROW] @CODE XML ,@ERRFLAG CHAR(1) = '0' OUTPUT AS SET NOCOUNT ON SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED DELETE tb_SampleTest WHERE CODE IN( SELECT Item.value('.', 'VARCHAR(20)') FROM @CODE.nodes('RecordList/ID') AS x(Item) ) IF @@ROWCOUNT = 0 SET @ERRFLAG = 200 SET NOCOUNT OFF 

获取string值删除

 <RecordList> <ID>1</ID> <ID>2</ID> </RecordList>