顯示包含「query」標籤的文章。顯示所有文章
顯示包含「query」標籤的文章。顯示所有文章

2011/03/08

"Update" SQL joining more than 1 tables

平時用CODE做, UPDATE SQL 都係好簡單, 但如果想做複雜少少既UPDATE, 其實亦可以COMBINE 埋 SELECT 一齊UPDATE , 但個SYNTAX有少少唔同

假設我select 左一堆node type係 "recipe" ,同profile_values 係"member"既row出黎

select * from node ,users ,profile_values 
where node.type='recipe' 
and users.uid = node.uid 
and profile_values.nid = node.nid
and profile_values.value='member'

之後我想將result 既某一個column (e.g. language )一次過update做新value
update node ,users ,profile_values 
set node.language ='sc_kit_cn' 
where node.type='recipe' and users.uid = node.uid 
and profile_values.nid = node.nid
and profile_values.value='member'

簡單講, 
就係將from 既table list 放去update後面
set 既column一定要簡番要update既table
where 果堆照keep番