Problem
I’m trying to delete records in a table with ids 163 to 265 using a SQL query.
This is what I tried to eliminate a smaller amount of rows.
DELETE FROM `table` WHERE id IN (264, 265)
Is there a query comparable to the above way for deleting 100’s of rows at a time? I’m also attempting to use this type of query but am unable to do so.
DELETE FROM `table` WHERE id IN (SELECT * FROM table WHERE id = )
Please provide me with the query in order for me to perform the above activity…
Asked by balu zapps
Solution #1
You can use IN: to delete items based on a list.
DELETE FROM your_table
WHERE id IN (value1, value2, ...);
You may also use IN: to delete based on the results of a query.
DELETE FROM your_table
WHERE id IN (select aColumn from ...);
(It’s worth noting that the subquery must only return one column.)
If you need to eliminate a range of values, you can use either BETWEEN or 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 by Barranka
Solution #2
BETWEEN is a word that can be used in a variety of ways.
DELETE FROM table
where id between 163 and 265
Answered by leppie
Solution #3
Please try this:
DELETE FROM `table` WHERE id >=163 and id<= 265
Answered by Keerthi
Solution #4
SELECT * FROM your_table ORDER BY DESC
Get the range you want to eliminate, for example, 3 to 10.
DELETE FROM your_table
WHERE id BETWEEN 3 AND 10;
In the BETWEEN Clause, make sure to include the minimum value fist.
Answered by Chamin Thilakarathne
Solution #5
4–7 ids should be removed.
DELETE FROM cats
WHERE id BETWEEN 4 AND 7;
By name
DELETE FROM cats
WHERE name IN ("Lucy","Stella","Max","Tiger");
Answered by MD SHAYON
Post is based on https://stackoverflow.com/questions/16029441/how-to-delete-multiple-rows-in-sql-where-id-x-to-y