I have two datasets: 1. ZipCodes and 2. Neighborhoods (think of them as like counties).
I want to join each neighborhood with which zipcodes cover it. Most neighborhoods will only be within one zipcode, but in some cases neighborhoods will straddle two. So for example:
Neighborhood 1 is inside 20001
Neighborhood 2 is inside 20002
Neighborhood 3 is inside 20001,20002
Here is what I have so far:
SELECT name, zipcode
FROM
neighborhood_names nn, dc_zipcode_boundries dzb
WHERE ST_Intersects(nn.the_geom, dzb.the_geom);
Note: Updated to within based on comments, now getting an answer for each neighborhood but still not able to get the Array function to respond as expected.
select nn.the_geom_webmercator, name, string_Agg(zipcode, ',') as zipcodeArr from
neighborhood_names nn, dc_zipcode_boundries dzb where ST_Intersects(nn.the_geom,dzb.the_geom)
and generally got errros: column "nn.the_geom_webmercator" must appear in the GROUP BY clause or be used in an aggregate function what am i doing wrong? – Matt617 Jun 14 '15 at 12:45