Mysql,从同一个表中的另一行复制一个单元格值

时间:2018-05-05 09:25:24

标签: mysql

如何从同一个表中的另一行复制单元格值?

UPDATE mytable SET myvalue=(SELECT myvalue FROM mytable WHERE id=2) WHERE id=11

它会显示错误消息:

Table 'mytable' is specified twice, both as a target for 'UPDATE' and as a separate source for data

谢谢

1 个答案:

答案 0 :(得分:1)

UPDATE mytable SET id=11, mycol=a.mycol FROM (SELECT mycol FROM mytable WHERE id=2) a