I am trying to the find the four closest building polygons to a junction point layer. I understand how to obtain this for a single point but am unsure of how to specify the four closest polygons for every point in my layer.
DROP TABLE IF EXISTS corner_buildings;
CREATE TABLE corner_buildings AS
SELECT buildings.geom AS buildgeom,
nodes.geom AS nodegeom
FROM buildings, nodes
WHERE nodes.objectid = 1
AND ST_DWithin(buildings.geom, nodes.geom, 200)
ORDER BY st_distance(buildings.geom, nodes.geom)
LIMIT 4;