| 1 | = Examples Join Tables = |
| 2 | |
| 3 | |
| 4 | An 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 | |
| 6 | For 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 | {{{ |
| 15 | CREATE TABLE parceljoin (id integer, ownername text); |
| 16 | |
| 17 | SELECT AddGeometryColumn('public', 'parceljoin','the_geom','4326','POLYGON',2); |
| 18 | |
| 19 | INSERT INTO parceljoin |
| 20 | SELECT p.id as id, o.ownername as ownername, p.the_geom as the_geom |
| 21 | FROM parcel p |
| 22 | LEFT JOIN owners o ON o.id = p.id; |
| 23 | |
| 24 | }}} |