John James John James - 11 months ago 103
MySQL Question

Pass array in Mysql query with nodejs

I have a simple query that I want to pass an array inside which has 5 items. I am using the

mysql
module so I know it can be done but am not doing the synatx right and therefore getting a syntax error.

Below is the query:

`UPDATE table1 SET table1.col=0 WHERE (table1.col2) IN = (?) AND table1.id=(SELECT ...);`,[arr]

//arr = [1,2,3,4,5];


I have tried:

`UPDATE table1 SET table1.col=0 WHERE (table1.col2) IN = (?,?,?,?,?) AND table1.id=(SELECT ...);`,[arr]`


but I still get a syntax error.

Answer Source

The syntax of the IN() predicate does not use =.

WHERE (table1.col2) IN = (?,?,?,?,?)

should be

WHERE table1.col2 IN (?,?,?,?,?)

Tip: you can (and should) check syntax yourself in the documentation, so you can get answers more easily than posting to Stack Overflow.

https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#function_in

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download