John James John James - 3 years ago 250
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

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 ...);`,[arr]

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

I have tried:

`UPDATE table1 SET table1.col=0 WHERE (table1.col2) IN = (?,?,?,?,?) AND ...);`,[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.

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