I've created a mass delete feature on my website where the user gets to select which rows they want to delete before pressing a delete button. It currently works by creating an array containing each selected row's id, before looping through that array and calling a delete query for each one. I was wondering if there is a way to do with with a single query, while keeping in mind that the user may want to keep a row that in between the rows they would like to delete.
Asked
Active
Viewed 1,266 times
1 Answers
0
You can use IN
clause for this.
Sample query may look like below
DELETE FROM table WHERE id IN (1, 4, 6, 7)

Menuka Ishan
- 5,164
- 3
- 50
- 66