2016-08-08 26 views
0

使用Postgres的,我有2个表:如何从其他表中获取匹配数据?

  • 的列SID,代理和邮政编码的第一个叫的领土。

  • 第二个叫postcodes,列id,邮编和几何。

如何将表格邮编中的几何列数据放入具有匹配邮编的表区域?

+0

你有没有尝试加入两个表。 –

回答

3

在查询:

select t.*, p.geometry 
    from territories as t left join postcodes p on t.postcode=p.postcode 

那只能如果没有在邮政编码表duplicateds邮政编码。

如果要更新表领土,首先添加列,然后更新:

update territories t set geometry = p.geometry 
    from postcodes p 
    where t.postcode=p.postcode