一尘不染

MySql-使用来自同一表的选择语句更新表

mysql

我正在尝试使用同一表中不同行(和不同列)中的值更新表中的行。尽管我的语法没有任何结果,但与此类似:这是代码(已更新):

UPDATE table1 AS t1 INNER JOIN
(SELECT field_id_46,field_id_47 FROM table1 WHERE entry_id = 36) AS t2
SET t1.field_id_60 = t2.field_id_46, t1.field_id_61 = t2.field_id_47
WHERE t1.entry_id = 45;

阅读 231

收藏
2020-05-17

共1个答案

一尘不染

update table as t1
inner join (
select field_id_46,field_id_47 from table where entry_id = 36) as t2
set t1.field_id_60 = t2.field_id_46,
    t1.field_id_61 = t2.field_id_47
where t1.entry_id = 45

或者,简单地

update table as t1,
(
select field_id_46,field_id_47 from table where entry_id = 36) as t2
set t1.field_id_60 = t2.field_id_46,
    t1.field_id_61 = t2.field_id_47
where t1.entry_id = 45
2020-05-17