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

I am trying to run an SQL query to delete rows with id from 163 to 265 in a table

I tried this to remove fewer lines

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

But when it comes to 100 lines at a time, is there any query that is similar to the method described above I am also trying to use this kind of query, but could not execute it

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

Please tell me the request to perform the above action ...

+45
sql sql-delete
Apr 16 '13 at 5:31 on
source share
5 answers

If you need to remove 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 the query, you can also use IN :

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

(Note that a subquery should only return one column)

If you need to delete depending on a range of values, either use BETWEEN or use the 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; 
+92
Apr 16 '13 at 5:35
source share

You can use BETWEEN :

 DELETE FROM table where id between 163 and 265 
+11
Apr 16 '13 at 5:35
source share

Please try the following:

 DELETE FROM `table` WHERE id >=163 and id<= 265 
+2
May 13 '16 at 4:34
source share
 Delete Id from table where Id in (select id from table) 
0
Oct 12 '17 at 6:35
source share
 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> 
-3
05 Oct '15 at 9:00
source share



All Articles