Query Relationship Classes?

7352
14
02-27-2017 10:56 AM
EricMahaffey1
Occasional Contributor

I can't seem to find anything that describes what to do with relationship classes once they are built.  Until now, all I can do is identify on the features in ArcMap, then click through the tree structure within the identify window in order to see the related records.  That's fine, but what about the ability to query the related features/records?  For instance, suppose you had a relationship class built for relating city blocks to the parcels within them.  I'd like to build a query to show all parcels that are "related" to a particular city block.  I just can't seem to find any guidance on doing these types of queries.  Thanks in advance.

0 Kudos
14 Replies
NealBanerjee
Occasional Contributor

I too have this problem and surprised more folks arent asking for it.  If I am understanding Eric's question, what I believe we really want is to be able to access and query a field in a separate table that is defined through a relationship class (or relate) using a SQL expression. 

For example if I have parcel table that has physical and economic information (acreage, value, etc.) joined through a common Parcel ID to an owner table that has information on owners (name, etc.).  If I "in" the owner table and I want to query owners associated with parcels that are greater than some size (say 5 acres), where parcel size is in the parcel table, it would be nice to do that "programatically" in code use SQL and/or Python rather than doing the query and clicking a button on the interface to select those records. 

This functionality was actually available back in the ArcInfo workstation days (using "Info and "Tables" ).  Back then you could name a relate, and then access fields in the related table using the relate name similar to example below:

select <relate name>//<related column name> > 5

select ownpar//area_ac > 5

If this functionality is somehow available now, I would love to know. 

JoeBorgione
MVP Emeritus

I just found this :  Select Related Records   Dated, but it also links to a gp tool Bruce Harold‌ wrote in '15.

I'd forgotten about the INFO style if relates; brings back memories!

That should just about do it....
0 Kudos
BruceHarold
Esri Regular Contributor

Actually my tool was to emulate the KEYFILE selection option in ArcPlot's various selection commands, it doesn't use relates.  Somebody can create an Ideas entry and we'll track it.  I used to use keyfile selects all the time.

0 Kudos
JoeBorgione
MVP Emeritus

Vote early and vote often....  https://community.esri.com/ideas/15991 

That should just about do it....
0 Kudos
MaazaMekuria
Occasional Contributor

I am not sure if this would help and i think it should work with both AGOL and ArcPro, I was pleasantly surprised to find and AGOL Python API method that queries related records  at https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html?highlight=related_reco... 

The only caveat is one has to sleuth out the relationship id.  If any of you how to query the relationship id from the feature layer , I would be grateful if you share with me.  I feel the API documentation is lacking in detail very little description is provided and there is scant sample code.   

0 Kudos