I have two polygon layers/tables in QGIS. The two layers represent (almost) the same spatial division (census boundaries). Basically, the polygons don't perfectly overlap because of differences in precisions between the two layers, but they should represent about the same census boundaries. Each layer has a "var" integer field.
My goal is to find the difference between the two layers' var values, polygon per polygon. So if two polygons' positions almost match, I want to substrat the value of one to the other, and attribute the result to one of the polygons.
I have done this thus far:
SELECT a.var, b.var, b.var - a.var as diff, b.geometry
FROM layer1 as a, layer2 as b
WHERE ST_Intersects(a.geometry, b.geometry);
But it results in way two many polygons. What is the proper way to achieve this?