QGIS – How to Select Entries Not in Another Layer

expressionqgis

I have 2 layers of polygons in QGIS which are layer1 and layer2.
they both have column id.

The goal is to select items in layer1 that not appear in layer2 using unique field id.

For example:

layer 1 has id: 1, 2, 3, 4, 5

layer 2 has id: 1, 2, 3, 4

by using expressions like

id not in layer2

How can I write the expression to have item 5 in layer 1 selected?

Best Answer

You can achieve that using an SQL Query in the DB Manager of QGIS.

You choose Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers you can then try queries like the following :

select ID from layer1 where ID not in (select ID from layer2)

Depending on the size of your tables it can be a bit time consuming ...