QGIS: Selecting Features from Two Polygon Layers in One Virtual Layer

polygonqgisqueryvirtual-layer

I have two polygon layers that partially overlap: buidings and plots. Each layer has 126 features.

I want to create a Virtual Layer that is simply an addition of the two layers, thus it should contain 254 features (all features from buildings + all features from plots).

This is what I tried:

select b.geometry, p.geometry as geom
from building as b, plot as p
select st_union (b.geometry, p.geometry) as geom
from building as b, plot as p

I also tried replacing st_union by combine. However, every time I get 15'876 features, thus 126 * 126 instead of 126 + 126 features.

How should the query be to get a simple addition of the features of both layers?

Best Answer

You should union the 2 selects like:

SELECT b.geometry
FROM building b
UNION
SELECT p.geometry
FROM plot p;