1

I am looking for ways to select features in attribute table which have same values but in different column.

In the picture below as you can see "fid_2" has values which match "fid" but they are different features (shown by black arrow). Here I have manually selected the feature which match but I want to be able to select all three features like the one below automatically. Any ideas?

enter image description here

When "Select by expression" used
enter image description here

When I used the Field calculator
enter image description here

1
  • 2
    Given the example it seems that an attribute join fid to fid_2 qgistutorials.com/en/docs/performing_table_joins.html might be helpful but be VERY careful with FIDs, they're transient. When joined a matched fid to fid_2 will have fully populated rows but an unmatched one will have empty joined columns. If there are more fields or more than one instance of a joined field the process becomes far more complicated. Oct 26, 2021 at 4:44

1 Answer 1

2

Use the "Select by expression" from the Selection Toolbar

selection

with the following expression:

array_contains(
    string_to_array(
        concatenate_unique("fid_2")
        ),
    "fid")

Usually fields like "id" and "fid" are integers, in this case use a slightly difference expression:

array_contains(
    string_to_array(
        concatenate_unique(
            to_string("fid_2")
            )
        ),
    "fid")

It uses the following functions: array_contains(), string_to_array(), concatenate_unique(), and to_string().

P.S. I do not really understand whether you need to select "fid" in "fid_2", or vise versa.

7
  • It says the expression in invalid. Plus the picture shared is only a part of the selection, I have to do it for a lot of data.
    – Anu Rai
    Oct 26, 2021 at 4:57
  • Please check the updates :)
    – Taras
    Oct 26, 2021 at 5:00
  • I used the second expression which showed false for all. Did not do the selection I wanted. I wanted to select these in a bid to dissolve those features into one and did not want to do it manually. Any further help will be highly appreciated.
    – Anu Rai
    Oct 26, 2021 at 5:21
  • That is weird. Can you please share a piece of your data or at least show how the above expression works/fails in your project for your layer?
    – Taras
    Oct 26, 2021 at 5:27
  • 1
    @Taras: proud to have an attribute bamed after you (OP's last screenshot)? ;-)
    – Babel
    Oct 26, 2021 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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