在update的時(shí)候不能更新select后的結(jié)果
示例:
update test.table1 a
set a.name='111'
where a.id = (select max(id) from test.table1)
這個(gè)會(huì)報(bào)錯(cuò),
可以通過(guò)連表解決
update test.table a
join (select max(id) as id from test.table) b
set t.name ='111'
where a.id = b.id
或
update test.table a ,(select max(id) as id from test.table) b
set a.name ='111'
where a.id = b.id
說(shuō)明:
update 時(shí),更新的表不能在set和where 中用于子查詢
update 時(shí),可以對(duì)多個(gè)表進(jìn)行更新
update 后面可以做任意查詢,這個(gè)作用相當(dāng)于from