Node JS mysql deleting multiple rows with an array of arrays

A solution for your problem is to use 'IN' inside your query:

var deleteRooms = [[3,23],[4,23],[5,23], [2,23]];

connection.query("DELETE FROM rate_plans_rooms WHERE (room_id, rate_plan_id) IN (?)",
    [deleteRooms],function(err,results){

    if(err) return console.log(err)
    else console.log('sended');
});

The accepted solution did not work for me as it would give an Error: ER_OPERAND_COLUMNS: Operand should contain 2 column(s) error. Instead, this worked for me:

var deleteRooms = [[3,23],[4,23],[5,23], [2,23]];
queryArray = Array(deleteRooms.length).fill('(?)'));

connection.query("DELETE FROM rate_plans_rooms WHERE (room_id, rate_plan_id) IN ("+queryArray.join(',')+")",
    [deleteRooms],function(err,results){

    if(err) return console.log(err)
    else console.log('sended');
});

Tags:

Mysql

Node.Js