# Buffer multiple roads to find points within and compare?

What I am trying to do is buffer a main st and a side street and get all of the points that intersect that buffer, however they need to be mutually exclusive. In the example below, my results would give me a duplicate at the intersection of Epping Forest Rd and Point No Point Dr.

Logic: I need to buffer Epping Forst Rd and get all points that intersect that buffer and buffer Point No Point Dr and get all points that intersect that buffer then compare both results and drop any points that are duplicate.

So far I have this SQL statement:

``````SELECT  aa_points.int_id
FROM    aa_points,
AND ST_Intersects(aa_points.the_geom_webmercator,
``````

That queries one road but I am at a loss on how to do the second road in a nested statement and how to compare/drop records.

• Do you want to completely drop those two points (so they are in neither selection), or just not have the same points in two selections? If the latter, what criteria determines which selection they should belong to? Aug 26, 2014 at 19:56

To begin with you might consider using ST_DWithin instead of creating a buffer and using ST_Intersects. It will be faster and simpler.

That being said, to get all the points that are in one buffer but not in both buffers you need to get the symmetric difference of both sets.

Symmetric differences look something like this: (a EXCEPT b) UNION (b EXCEPT a).

For your specific problem try the following:

``````WITH
eppingforest AS
(
SELECT aa_points.int_id
),
pointnopoint AS
(
SELECT aa_points.int_id
WHERE road_ln.st_nam = 'POINT NO POINT'
),
aexceptb AS
(
SELECT * FROM eppingforest
EXCEPT
SELECT * FROM pointnopoint
),
bexcepta AS
(
SELECT * FROM pointnopoint
EXCEPT
SELECT * FROM eppingforest
),
symmetricpoints AS
(
SELECT * FROM aexceptb
UNION
SELECT * FROM bexcepta
)
SELECT aa_points.int_id
FROM symmetricpoints
;
``````

If you don't need the symmetric difference just no duplicates try the following:

``````SELECT DISTINCT aa_points.int_id
WHERE road_ln.st_nam IN ('EPPING FOREST','POINT NO POINT')
``````SELECT aa_points.int_id