2011-03-14 183 views
0

我有以下查詢幫助的SQL查詢

select * from Properties 
join PPHL on PPHL.postcode = Properties.postcode 
and PPHL.name = Properties.propertyname 
and PPHL.id <> Properties.propertycode 
where Properties.clientid = 1 

我想更新從該查詢從PPHL表中的id結果所有的屬性,沒有人知道正確的SQL我需要做這個?我在MySQL 5上運行這個。

回答

2

set子句在表連接之後進行。請參閱MySQL documentation for UPDATE獲取語法幫助。

UPDATE Properties 
    JOIN PPHL ON PPHL.postcode = Properties.postcode 
      and PPHL.name = Properties.propertyname 
      and PPHL.id <> Properties.propertycode 

SET Properties.propertycode = PPNL.id 
WHERE Properties.clientid = 1