I'm trying to create a shapefile of a state. I have a map of US zipcodes that I downloaded from the US Census and I want do create a shapefile of zipcodes in Florida.
I ran this query which produces a shapefile that I expected, however when I examine the attribute table in QGIS, I see that there are duplicates of the zip code. The same thing occurred when I modify the query to intersect a specific state using a shapefile of US DMAs (Flordia has 11 DMAs, but the attribute table has 1,107 rows, mostly duplicates). Answers regarding how to fix duplicate rows in an attribute table has come up unsatisfactory. An example of my output is here:
My query is below:
"SELECT geoid10, geom FROM (
SELECT uszips.geoid10, (ST_Dump(ST_Intersection(uszips.geom, fl.geom))).geom
FROM uszips, fl
WHERE ST_Intersects(uszips.geom, fl.geom)) t
WHERE ST_GeometryType(geom) = 'ST_Polygon';