Select by Expression with Subquery

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Select by Expression with Subquery

Altergott, Randy (CCI-Southwest)

Hi QGIS users,

I’m new to QGIS and this is my first question.

Can I use QGIS “Select by Expression” to select all features in a vector layer where the “name” field value is also found within another layer (delimited text layer with no geometry)? I get a syntax error when using the following SQL.

 

“NAME” IN (SELECT “NAME” FROM ‘LAYER2’)

 

I’m using the “Map Layers” menu to add the layer name, so it actually displays something like ‘LAYER2_ca36271a_8ec7_4aa7_a36c_67418104f66c’ instead of just ‘LAYER2’.

 

Thanks,

Randy

 


_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Reply | Threaded
Open this post in threaded view
|

Re: Select by Expression with Subquery

Martin Bain

Hi Randy,

This might work in QGIS 3 – it’s untested because I’m currently on a machine with QGIS 2.18 (where the @parent variable is unavailable)

 

aggregate( 'LAYER2','count',"NAME","NAME"=attribute(@parent, 'NAME')) > 0

 

The other way might be to create a join to your target layer and then select the rows where the value of joined column is not null.

 

Cheers,

Martin.

 

From: Qgis-user [mailto:[hidden email]] On Behalf Of Altergott, Randy (CCI-Southwest)
Sent: Tuesday, 18 June 2019 3:41 AM
To: [hidden email]
Subject: [Qgis-user] Select by Expression with Subquery

 

Hi QGIS users,

I’m new to QGIS and this is my first question.

Can I use QGIS “Select by Expression” to select all features in a vector layer where the “name” field value is also found within another layer (delimited text layer with no geometry)? I get a syntax error when using the following SQL.

 

“NAME” IN (SELECT “NAME” FROM ‘LAYER2’)

 

I’m using the “Map Layers” menu to add the layer name, so it actually displays something like ‘LAYER2_ca36271a_8ec7_4aa7_a36c_67418104f66c’ instead of just ‘LAYER2’.

 

Thanks,

Randy

 


_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user