Changes between Initial Version and Version 1 of UsersWikiExamplesJoinTables


Ignore:
Timestamp:
Apr 14, 2009, 8:54:39 AM (15 years ago)
Author:
pierre
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiExamplesJoinTables

    v1 v1  
     1= Examples Join Tables =
     2
     3
     4An attribute join is often needed when you need to associate a tabular data source with features. A left join is appropriate in this case since we want to retain all the spatial features and append the tabular attributes only where a match occurs.
     5
     6For example, lets say we have two tables:
     7
     8 * parcel  (with an "id" column and spatial geometry)
     9 * owner (with an "id" column and owner information for that parcel id)
     10
     11----
     12
     13
     14{{{
     15CREATE TABLE parceljoin (id integer, ownername text);
     16
     17SELECT AddGeometryColumn('public', 'parceljoin','the_geom','4326','POLYGON',2);
     18
     19INSERT INTO parceljoin
     20SELECT p.id as id, o.ownername as ownername, p.the_geom as the_geom
     21FROM parcel p
     22LEFT JOIN owners o ON o.id = p.id;
     23
     24}}}