I am trying to create a selection. First, I select records which have Null value in "Status" column ("Status" is NULL"). Then it starts to be a bit tricky. I want to select all the records which have the same number as selected "Status" records. Is it possible to do it in QGIS?

First, I select null values using "Status" is NULL expression.

First step

Then I need to add something to take ID values and use it to create a new selection.

The final selection should look like that:

Second step

I am using QGIS 2.16.

  • 1
    Since you first select "Status" IS NULL, what do you mean by "records having the same number"?
    – Cezar B
    Feb 18, 2017 at 14:02
  • I mean records with the same ID as selected "STATUS" records. So in this case it all with number 1.
    – Losbaltica
    Feb 18, 2017 at 14:06

1 Answer 1


You may run this code from the Python Console (it works on the active layer):

layer = iface.activeLayer()
query_1 = '"Status" is NULL'
selection = layer.getFeatures(QgsFeatureRequest().setFilterExpression(query_1))
selected_ids = [k["ID"] for k in selection]

ids = []
for feat in layer.getFeatures():
    if feat["ID"] in selected_ids:
layer.setSelectedFeatures([l for l in ids])

You will obtain the desired output:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.