SQL: Updating table within a table

时间:2017-03-14 23:02:14

标签: mysql sql

How can you update the value inside of a table that is within another table?

Say you have a table called ratings that has this structure:

+----------+---------+--------+
| video_id | user_id | rating |
+----------+---------+--------+
|      5   |   158   |    4   |
|      5   |  5875   |    1   |
|      5   |   585   |    5   |
+----------+---------+--------+

How could you update the value of the second row of rating? So to change the second row of rating from 1 to say.. 12.

How do you even select that value?

EDIT: It turns out I had misunderstood the situation. Instead of the columns containing variables, there was a separate column containing values which I wanted to change depending on the other columns.

1 个答案:

答案 0 :(得分:1)

我没有看到“桌子中的桌子”在哪里发挥作用......对我来说它看起来像一个标准update

update ratings
set rating = 12
where video_id = 5
  and user_id  = 5875