Delete lines within polygon
You can use Select By location then delete selected rows in QGIS or join by within:
delete from ok_jl_riks_copy where id in ( select sub1.id from (select * from ok_jl_riks_copy jl) sub1 inner join (select wkb_geometry from ok_ak_riks ak) sub2 on st_within(sub1.wkb_geometry, sub2.wkb_geometry) )
All lines within the polygons are deleted:
DELETE FROM <lines> AS ln WHERE EXISTS ( SELECT 1 FROM <poly> AS pl WHERE ST_Within(ln.geom, pl.geom) );
ST_Within check hits the first
TRUE (selecting a truthy
1), the sub-query terminates for the current row (no matter if there were more than one hit).
This is among the most efficient ways for when a table has to be traversed by row (as in an
UPDATE/DELETE), or otherwise compared against a pre-selection (of e.g.
As the error message says you should only return a single column, so try:
delete from lines_test2 where id = ( select a.id from lines_test2 a, straten b where st_intersects(a.geom, b.geom));
This assumes you have a unique ID column in your
lines_test2 data table.