I have a layer with points and a layer of polygons. I can find all the polygons that contains at least one point inside itself by:
SELECT polygons.id
FROM polygons, points
WHERE ST_Intersects(polygons.geom, points.geom)
But what if I just want the opposite of this: select all polygons that contains no points?
SELECT polygons.id
FROM polygons, points
WHERE NOT ST_Intersects(polygons.geom, points.geom)
This last query actually returns all polygons since the condition NOT ST_Intersects(polygons.geom, points.geom)
can be true for some points/polygons pairs (there is always a point somewhere which is not inside a polygon).