I have two line layers in QGIS, of which one layer (layer 2 - yellow in the image) is a geometrical subset of the other (layer 1- blue in the image). The two layers also differ in their values of a column. I want to sum the values of layer 2 (yellow) to the values of layer 1 (blue), where their geometries are equal.
I created a virtual layer like this:
select
a.DTV + b.DTV as DTV,
a.geometry
from layer1 a
left join layer2 b
on st_equals(a.geometry, b.geometry)
However, this returns a layer with a column 'DTV' which has the sum of the values in the two layers where their geometries are equal, but everywhere else it is NULL
.
What I want is a column which has everywhere else the values of layer 1.
In other words, I want to create a 'copy' of layer 1 but change the values where its geometry is overlapping with layer 2. How do I need to adjust the SQL accordingly?