我有一个问题,我正在尝试更新批量更新以从anotehr列替换一列的值。
以下是我从以下查询生成的数据
ID CodeID credit Image creator
47774 5635 none 5635.jpg Freshy
47790 5643 none 5643.jpg Fresh
47792 5643 none 5643AB.jpg Fresh
47793 5643 none 5643FF.jpg Fresh
47795 5643 none 56431.jpg Fresh
47796 5643 none 56434B.jpg Fresh
最后一列{Creator}来自以下的加入:
我想在信用列中填写相同的创建者值,怎么做
select mp.id, codeid, credit, image, creator
from mp inner join mm on mm.id = mp.codeid
where credit = 'none'
尝试像这样的更新
update mp SET credit = (select creator
from mp inner join mm on mm.id = mp.modid
where credit = 'none')
最终出现错误:
[Err] 1093 - You can't specify target table 'mods_pics_copy' for update in FROM clause
可能有某种方法可以做到这一点
答案 0 :(得分:0)
使用此语法
UPDATE mp
JOIN mm ON mm.id = mp.codeid AND credit = 'none'
SET mp.credit = mm.creator;
答案 1 :(得分:0)
错误在SET中: 在这里你必须放置列名,而不是条件
update mp SET columnname where credit = somecondition