'How to update a table based on a raw dataset?

I have a table like this:

// users
+---------+------------+
| user_id | reputation |
+---------+------------+
| 1       | null       |
| 2       | null       |
+---------+------------+

Also I have an array like this: [1 => 15, 2 => 83]. I can parse that array and restruct it to any case needed. I want to know how can I update that value to that table like this:

// users - expected result
+---------+------------+
| user_id | reputation |
+---------+------------+
| 1       | 15         |
| 2       | 83         |
+---------+------------+

An idea how can I do that?


I want a query similar to this:

update users u
join ( ... ) as temp
on u.user_id = temp.user_id
set u.reputation = temp.rep


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source