0

So suppose I have a simple query like below; (its an example, I know that is not proper syntax, but the logic stays the same).

for(let i=1; i<len; i++){
    UPDATE table1 
    SET table1.col1 = i 
    WHERE table1.id = arr[i] 
}

I want to avoid doing 10 or 20 queries, so I was wondering how to remove the for, perhaps something like

UPDATE table1 
SET table1.col1 = ? #<<how to add the increment here.>>
WHERE table1.id IN (arr)
John James
  • 587
  • 3
  • 8
  • 19

1 Answers1

0

You can convert the array into a String of comma separated values and use it in the query.

How you convert array into String of such values depends on which language you are using in the application, e.g.:

  • Here's an example of how to do it in php
  • Here's an example of how to do it in Java
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • My problem is not how to include the arr in the IN. I am trying to increase the col1 by 1 for every element in the arr. – John James Oct 15 '17 at 12:33