Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

I was trying to run a SQL query to delete rows with id's 163 to 265 in a table

I had tried this to delete less number of rows

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

However, if I want to delete 100s of rows at the same time, is there any other query that is similar to above method. I also tried using the below kind of query but failed to execute it.

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

Please someone suggest me a query to do above task .

1 Answer

0 votes
by (12.7k points)

If you would like to delete based on a list, you'll use IN:

DELETE FROM your_table
WHERE id IN (value1, value2, ...);

If you would like to delete based on the results of a query, you'll also useIN:

DELETE FROM your_table
WHERE id IN (select aColumn from ...);

(Notice that the subquery must return just one column)

If you would like to delete based on a range of values, either you use BETWEEN otherwise, 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;

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
4 answers
0 votes
0 answers
asked Dec 29, 2020 in SQL by biscottob (120 points)

Browse Categories

...