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, 2022 in Database by Kithuzzz
• 38,010 points
4,849 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, 2022 by narikkadan
• 63,420 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, 2022 in Database by Kithuzzz
• 38,010 points
2,226 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, 2022 in Database by Kithuzzz
• 38,010 points
1,355 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, 2022 in Database by Kithuzzz
• 38,010 points
1,661 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, 2022 in Database by Kithuzzz
• 38,010 points
502 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, 2022 in Database by Vaani
• 7,020 points
590 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, 2022 in Others by Soham
• 9,700 points
898 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, 2022 in Database by Kithuzzz
• 38,010 points
525 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,538 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, 2022 in Database by narikkadan
• 63,420 points
37,054 views
0 votes
1 answer

How to execute function in SQL Server 2008

The function appears not to be being ...READ MORE

answered Sep 11, 2022 in Database by narikkadan
• 63,420 points
706 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