我正在尝试更新特定字段并将其设置为等于同一字段中一行的值。
到目前为止我尝试过的是:
mysql> UPDATE tblitem SET imagefilename = (SELECT imagefilename from tblitem where itemid=2) where itemid=1'
1093 - You can't specify target table 'tblitem' for update in from clause
我在这里要做的是将 itemid 1 的值更新为 itemid 2 的值。
这可能吗?提前谢谢你。
最佳答案
在 MySQL 中,如果你在表上执行 UPDATE
/INSERT
/DELETE
查询,你不能引用上述内部查询中的表。一种解决方法是在内部查询中使用子查询:
UPDATE tblitem
SET imagefilename =
(
SELECT imagefilename
FROM (SELECT * FROM tblitem) AS t
WHERE itemid = 2
)
WHERE itemid = 1
关于mysql - 更新字段设置为同一字段中行的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39908284/