AnsweredAssumed Answered

"Advanced" query selection of entities through a relationship

Question asked by raul.jimenezesri-es-esridist Employee on Sep 17, 2019
Latest reply on Sep 26, 2019 by raul.jimenezesri-es-esridist

Requirement: I want/need to do this using hosted feature services in ArcGIS Online

I'm just trying to do something like this with just one REST API call:

SELECT table1.*
FROM   table1, table2
WHERE  table1.primary_key = table2.foreign_key
       AND table1.attr = 'Value1'
       AND table2.attr = 'Value2'


Now I'm going to explain the approach I have been following and the issue I'm facing, but maybe the approach is wrong.



  1. I created a file geodatabase in ArcGIS Pro with two Feature Classes (table1 & table2)
  2. I created a relationship class where: table1.primary_key = table2.foreign_key
  3. I published it in ArcGIS Online


Then I tried to do a similar query to this one using the query related records end point from the REST API but I couldn't:

  • First, I noticed that it is not possible to set the objectIds param to "*" (which I don't quite understand why) <- but I could manage it by setting all the objectIds manually.
  • But the real problem I found was that in the definitionExpression param I could only use attributes from one table/layer (the related one) but not from both of them.


So, I'm not sure if the only way to solve this is programmatically by:

  1. First query one table to get only the OBJECTIDs that meet all the criteria established to this table
  2. And then use the query related records setting the objectIds to those I recovered in step 1 and set the definitionExpression to add the pending criteria (the one to filter also the data within the related table).


Is this the way to solve what I'm trying to achieve or there's some way to do it with just one API request?.


Best regards,


BTW: I also tried doing a JOIN in memory and then selecting features by attributes and it worked in ArcGIS Pro, but I couldn't publish that on ArcGIS Online