discuz forum group的同一个表中更新数据

UPDATE bbs_forum_forum AS ff,(SELECT fid,NAME FROM bbs_forum_forum) AS f SET ff.fup=f.fid



WHERE ff.parent_forum=f.name AND ff.parent_forum IS NOT NULL AND ff.parent_forum <> ''



mysql 同一表中更新

test 表格 

有2个列 

id int PK 

name varchar(50) 

orgId int FK 



要把name列设置为某个复杂条件的 id 列的值,比如orgId=1

update test t set name=(select id from test where orgId=1 and id=t.id)  

直接执行出现这个异常 

错误:You can't specify target table 't' for update in FROM clause 

修正方式如下

update test t, (select id,name from test where orgId=1) t2 set t.name=t2.id where t2.id=t.id  

 

你可能感兴趣的:(discuz)