i need to do a multiple row delete query with the where clause in list (id1,id2..) But since we don't have lists in JS i'm having a problem with passing the parameters to the query.This is my code:
let list =[1,2,..];
let Query = 'DELETE FROM Table WHERE id IN (?)';
connection.query(Query,list, function (err, result) {
`enter code here`
};
when i pass it this way and after logging the mysql server to a Logfile i see that it actually passes only the first id.
PS : i tried without the parentheses around ? and also doing a Array.join on the list but both didn't work.
Read in document of https://github.com/mysqljs/mysql#performing-queries (if you use this lib to connect mysql)
let list =[1,2,..];
let Query = 'DELETE FROM Table WHERE id IN (?)';
// values param need is a array of value to binding to "?"
// you can try [list.toString()] if the block above not working
connection.query(Query,[list], function (err, result) {
`enter code here`
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With