How to delete multiple rows in SQL where id = (x to y)

雨燕双飞 提交于 2019-11-27 17:22:49

If you need to delete based on a list, you can use IN:

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

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)

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;

or

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

You can use BETWEEN:

DELETE FROM table
where id between 163 and 265
Keerthi

Please try this:

DELETE FROM `table` WHERE id >=163 and id<= 265
Denny
Delete Id from table where Id in (select id from table)
ThienPhuc
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

Get string value delete

<RecordList>
    <ID>1</ID>
    <ID>2</ID>
</RecordList>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!