I'm working with mysql and golang. Let's say I have a table with the following columns: ID, value1
Given an array of IDs that I want to update, as well as a an array of value1, where ID[i] corresponds to the value of value1[i]. Is it possible for me to use the array and update the multiple rows in one query?
I've seen the case-when-then query, which would require quite a bit of formatting, hence I was wondering if there is a simpler way to do it. Furthermore, is there a way to extend this if there a more columns.
For example, given an array of ID = [1, 2, 3], val1 = [2, 4, 5], val2 = [3, 5, 6], we updated row with ID = 1, to be val1 = 2, val2 = 3 and so on. In this "multiple columns" case, the case-when-then query would be overly complicate since one case works for one column.
The resulting table would then look like this:
| ID | val1 | val2 |
|---|---|---|
| 1 | 2 | 3 |
| 2 | 4 | 5 |
| 3 | 5 | 6 |
Would appreciate this!