Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete from a table where ID is in a list of IDs?

if I have a list of IDs (1,4,6,7) and a db table where I want to delete all records where ID is in this list, what is the way to do that?

like image 461
leora Avatar asked Apr 11 '10 00:04

leora


People also ask

How do I delete multiple records in a table?

There are a few ways to delete multiple rows in a table. If you wanted to delete a number of rows within a range, you can use the AND operator with the BETWEEN operator. DELETE FROM table_name WHERE column_name BETWEEN value 1 AND value 2; Another way to delete multiple rows is to use the IN operator.

How do I delete multiple records from a table in SQL?

To remove one or more rows in a table: First, you specify the table name where you want to remove data in the DELETE FROM clause. Second, you put a condition in the WHERE clause to specify which rows to remove. If you omit the WHERE clause, the statement will remove all rows in the table.

How do you remove information from a table?

Select all the cells in the table, click Clear and pick Clear All. Tip: You can also select the table and press Delete. If you want to keep the data without the table format, you won't be able to do that in Excel for the web. Learn more about using the Excel desktop application to convert a table to a data range.


2 Answers

Your question almost spells the SQL for this:

DELETE FROM table WHERE id IN (1, 4, 6, 7) 
like image 96
Matti Virkkunen Avatar answered Oct 02 '22 22:10

Matti Virkkunen


delete from t where id in (1, 4, 6, 7) 
like image 36
Carl Manaster Avatar answered Oct 02 '22 22:10

Carl Manaster