0

Currently I am working on my Web site Frontend: Vue Backend: Node.js

I am trying make a function which allows managers to delete user.

While making some SQL code for delete user information, I comes to my mind that

I cannot expect number of user deleted by manager..

It could be one, two or more.

So, please advice me how to tackle with this situation. I want to finish this in a single SQL sentence.

Thank you very much.

I have tried to make SQL codes like this

DELETE FROM user_table WHERE user_id = ${1} AND ${2} AND ${3} or more.....
I want to know a condition use for unexpected number of user Input

  • You can use ```DELETE FROM `table` WHERE id IN ( )``` or ```DELETE FROM `table` WHERE id BETWEEN `col` and `col```, you also ask existed question https://stackoverflow.com/questions/16029441/how-to-delete-multiple-rows-in-sql-where-id-x-to-y – Amir Jani Nov 30 '22 at 05:30

1 Answers1

0

use IN

let user_ids_to_delete = req.body.user_ids;   //example : [1,2,3,4]

let query = `DELETE FROM user_table WHERE user_id IN(${user_ids_to_delete});`
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71