Title edited. Originally "1:M Join — Select By Attributes handling nulls incorrectly."
ArcGIS Pro 3.2.2; File Geodatabase:
I've joined TABLE_A to TABLE_B via common ASSET_ID text fields using Add Join. The join is one-to-many: 1 row in TABLE_A to 4 rows in TABLE_B.
I want to select from TABLE_B.ROAD_NAME (text) where ROAD_NAME is null. However, Select By Attributes doesn't seem to work correctly. It selects all four rows, regardless if ROAD_NAME is null or not.
Video:
Notes:
I don't understand how that issue has been around since ArcGIS Pro 2.6.8 (or earlier) and is also in 3.2.2. How could such a serious issue not have been fixed as of 3.2.2?
Solved! Go to Solution.
@Bud , found this: https://support.esri.com/en-us/bug/the-select-by-attributes-tool-does-not-select-only-reco-bug-00015...
BUG-000154798: The 'Select By Attributes' tool does not select only records with specified field values added through a one-to-many join but instead selects all records with duplicate ObjectIDs.
@Bud, that's strange.
I tried same workflow on 3.1.0 and couldn't reproduce this issue...I also used 'Add Join' tool..
What if you use 'Join Field' gp tool, does the issue occur?
What if before join you run 'Calculate Field' tool on <Null> fields and run the query:
Then, perform a join and run 'Select By Attribute' tool?
@Bud I realized that I performed 1:1 join, my bad!
Yes, the issue does occur with 1:M join:
It's should be logged as a BUG.
@Bud , found this: https://support.esri.com/en-us/bug/the-select-by-attributes-tool-does-not-select-only-reco-bug-00015...
BUG-000154798: The 'Select By Attributes' tool does not select only records with specified field values added through a one-to-many join but instead selects all records with duplicate ObjectIDs.
Your testing in 3.1.0 and that bug are very helpful. Thanks! I’m investigating.
I noticed that bug was submitted in December 29, 2022. I’m surprised the issue hasn’t been fixed yet; I view it as high priority.
My users are starting to get the impression that ArcGIS Pro can’t be trusted when it comes to tabular analysis and are looking for alternative software solutions that can be trusted. Related issue: Add Join not keeping all target features and Esri Case #03387420 - Definition query on join returns incorrect rows.
If anyone from Esri sees this, can I suggest that this issue be made a priority? I imagine the last thing Esri wants is for users to not trust ArcGIS Pro when it comes to querying GIS data.
@GeeteshSingh07 As the bug suggests, the issue isn't specific to nulls. It applies to any value. The bug title described it fairly well.
@Bud , I agree..and should be fixed!
It turns out the issue doesn't only apply to Select By Attributes. It also applies to manual selections.
With a 1:m join, if I manually select one of the rows that is 1:M, then all rows in the 1:M group will get selected, which is incorrect.
Video (using different sample data):
Since this issue is specific to 1:M joins, a possible workaround is to make the join 1:1 instead of 1:M:
Or, to control what related record gets used in a 1:1 join, use this as the SQL expression in a Make Query Table (screenshot) :
table_b.objectid IN (SELECT objectid FROM table_b t2 WHERE t2.b_id = table_b.B_id ORDER BY b_text_field ASC FETCH FIRST ROW ONLY)
SQL expression source: Join — Control what related record gets used
The Make Query Table should include the OBJECTID field, since the SQL expression above references the OBJECTID.
Then, join to the Make Query Table.
The benefit of this approach is that it avoids issues with joining to a table that has a definition query, such as Add Join not keeping all target features and other bugs. The Make Query Table hides/embeds the SQL expression within the layer (it doesn't create a definition query), so that's how the usual "joining to a table with definition query" issues are avoided.
Also, as mentioned in a previous comment, definition queries don't have this problem. The problem is specific to selections. So in some cases, maybe a definition query could be used instead of a selection.
Other alternatives: