我正在尝试使用同一个表中不同行(和不同列)的值来更新表中的行.虽然我的语法没有产生任何结果:这是代码(更新):
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;
Run Code Online (Sandbox Code Playgroud)
Nic*_*ssu 53
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
Run Code Online (Sandbox Code Playgroud)
或者,简单地说
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
Run Code Online (Sandbox Code Playgroud)
小智 12
添加..
相同的表,有一个寄存器
UPDATE table t1
INNER JOIN table t2 ON t2.entry_id = t1.entry_id
SET t1.field_id_60 = t2.field_id_60,
t1.field_id_61 = t2.field_id_61
Run Code Online (Sandbox Code Playgroud)
您可以使用内部联接更新,如下所示:
UPDATE table1 AS t1
INNER JOIN table1 AS t2
SET t1.field_id_60 = t2.field_id_46,
t1.field_id_61 = t2.field_id_47
WHERE t1.entry_id = 54;
Run Code Online (Sandbox Code Playgroud)