2011-03-14 149 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