How to delete multiple rows in SQL where id x to y

0 votes

I'm attempting to use a SQL query to remove records from a table with ids 163 to 265. I experimented with this to eliminate less rows.

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

But is there a query similar to the one above that can delete hundreds of rows at once? I tried to utilize this type of query as well, but I was unable to do so.

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

Please tell me the query to do the above action.

Sep 16 in Database by Kithuzzz
• 12,240 points
39 views

1 answer to this question.

0 votes

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;
answered Sep 17 by narikkadan
• 20,880 points

Related Questions In Database

0 votes
0 answers

How to ALTER multiple columns at once in SQL Server

ALTER the data types of several columns in ...READ MORE

Aug 12 in Database by Kithuzzz
• 12,240 points
107 views
0 votes
0 answers

How to find sum of multiple columns in a table in SQL Server 2005?

I have a table Emp which has these rows: Emp_cd ...READ MORE

Aug 19 in Database by Kithuzzz
• 12,240 points
101 views
0 votes
0 answers

How to Return Multiple Values from CASE clause in Where Condition

I have a condition where utilizing the ...READ MORE

Aug 25 in Database by Kithuzzz
• 12,240 points
23 views
0 votes
0 answers

How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

In one ALTER TABLE statement, I would ...READ MORE

Sep 2 in Database by Kithuzzz
• 12,240 points
23 views
0 votes
1 answer

How to delete duplicate rows in SQL Server?

CTEs and ROW_NUMBER can be combined together which will ...READ MORE

answered Feb 10 in Database by Vaani
• 7,020 points
108 views
0 votes
1 answer

How to delete duplicate rows in SQL Server?

To answer your query, note that CTEs ...READ MORE

answered Feb 10 in Others by Soham
• 9,330 points
196 views
0 votes
0 answers

How can I delete using INNER JOIN with SQL Server?

In SQL Server 2008, I want to ...READ MORE

Aug 23 in Database by Kithuzzz
• 12,240 points
26 views
0 votes
1 answer

Which query to use for better performance, join in SQL or using Dataset API?

DataFrames and SparkSQL performed almost about the ...READ MORE

answered Apr 19, 2018 in Apache Spark by kurt_cobain
• 9,390 points
1,000 views
0 votes
1 answer

Multiple rows to one comma-separated value in Sql Server

Test Data DECLARE @Table1 TABLE(ID INT, Value INT) INSERT ...READ MORE

answered Sep 17 in Database by narikkadan
• 20,880 points
25 views
0 votes
1 answer

SQL WHERE ID IN (id1, id2, ..., idn)

Option 1 is the only good solution. Why? Option ...READ MORE

answered Sep 12 in Database by narikkadan
• 20,880 points
42 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP