用第二个 table 中的值替换 mySQL table 中的列值
Replace column values in mySQL table with values from a second table
- 我有一个名为 "ONE" 的 table,其中有一列 "Names"。
- 我有第二个 table,名为 "TWO",有两列:"Old_Names" 和 "New_Names"。
- 我想用 table "TWO".
中的 "Old_Names" 替换 table "ONE" 中的 "Names"
- "Names" 中的值与我 table 中 "Old_Names" 中的值相同。
我正在尝试这样做,但在 mySQL 上出现错误:
update ONE set (ONE.Names=TWO.New_Names)
from ONE
join TWO on (ONE.Names=TWO.Old_Names);
update ONE
join TWO on ONE.Names = TWO.Old_Names
set ONE.Names = TWO.New_Names
查看更新查询:
update one o
join two t on ( o.names = t.old_names )
set O.names = t.new_names;
连接子句必须写在查询的开头=>
http://sqlfiddle.com/#!9/9f292c
- 我有一个名为 "ONE" 的 table,其中有一列 "Names"。
- 我有第二个 table,名为 "TWO",有两列:"Old_Names" 和 "New_Names"。
- 我想用 table "TWO". 中的 "Old_Names" 替换 table "ONE" 中的 "Names"
- "Names" 中的值与我 table 中 "Old_Names" 中的值相同。
我正在尝试这样做,但在 mySQL 上出现错误:
update ONE set (ONE.Names=TWO.New_Names)
from ONE
join TWO on (ONE.Names=TWO.Old_Names);
update ONE
join TWO on ONE.Names = TWO.Old_Names
set ONE.Names = TWO.New_Names
查看更新查询:
update one o
join two t on ( o.names = t.old_names )
set O.names = t.new_names;
连接子句必须写在查询的开头=> http://sqlfiddle.com/#!9/9f292c