<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Definition queries on related tables in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/definition-queries-on-related-tables/m-p/1073103#M42572</link>
    <description>&lt;P&gt;There are a few possibilities, depending on what you're working with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have an Enterprise geodatabase, showing the latest record is really easy: Create a query layer (stored in the map document) or a database view (stored in the database) with the follwing SQL:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;SELECT t1.*, t2.*
FROM Table1 t1
INNER JOIN (
  SELECT Location_ID, MAX(Date) MaxDate
  FROM Table2
  GROUP BY Location_ID
) MaxDates
ON t1.Location_ID = MaxDates.Location_ID
INNER JOIN Table2 t2
ON MaxDates.Location_ID = t2.Location_ID AND MaxDates.MaxDate = t2.Date&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Both tools can be found in the DataManagement toolbox in the toolset "Layers and Table Views". However, making sure that the record is within the boundaries would be more complcated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you work in ArcGIS Pro, you can use Attribute Rules.&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.7/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/2.7/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Constraint Rule
// Table 2
// Triggers: Insert, Update
// Rejects the edit if the Recorded_Value is not within the upper and lower limits defined in Table 1

// load table 1
var tbl_1 = FeatureSetByName($datastore, "Table1", "*", false)

// filter table 1 by Location_ID
var loc_id = $feature.Location_ID
var loc = First(Filter(tbl_1, "Location_ID = @loc_id"))

// test if value falls within bounds, return true or false
var val = $feature.Recorded_Value
if(val &amp;gt;= loc.Lower_Limit_m &amp;amp;&amp;amp; val &amp;lt;= loc.Upper_Limit_m) {
  return true
}
return false&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Rule
// Table 2
// field: Recorded_Value
// Triggers: Insert
// If you add a new record to Table 2, the Recorded_Value will be written into Table1.CurrentValue_m
// This assumes that the record you add is actually the latest one!

// load table 1 and get the globalID of the location
var loc_id = $feature.LocationID
var g_id = First(Filter(FeatureSetByName($datastore, "Table1", ["Location_ID", "GlobalID"], false), "Location_ID = @loc_id")).GlobalID

// write the Rcorded_Value into Table1.Current_Value_m
return {
  "result": $feature.Recorded_Value,
  "edit": [
    {
      "className": "Table1",
      "updates": [
        {"globalID": g_id, "attributes": {"Current_Value_m": $feature.Recorded_Value}},
      ]
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If none of that works for you, you can use a Python script, but you'd have to manually run it every time you insert new records.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Jun 2021 07:42:47 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2021-06-28T07:42:47Z</dc:date>
    <item>
      <title>Definition queries on related tables</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-queries-on-related-tables/m-p/1072452#M42496</link>
      <description>&lt;P&gt;I have a point feature layer containing information about water monitoring locations. This includes a unique location ID, upper and lower limits for the recorded values and (what I want to be) the current value at that location. (Table 1)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Table 1:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20%" height="24px"&gt;Gid&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;Location_ID&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;Upper_Limit_m&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;Lower_Limit_m&lt;/TD&gt;&lt;TD width="20%" height="24px"&gt;Current_Value_m&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20%" height="39px"&gt;1&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&lt;P&gt;GW 1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&lt;P&gt;880&lt;/P&gt;&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;850&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20%" height="39px"&gt;2&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&lt;P&gt;GW 2&lt;/P&gt;&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;886&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;856&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="20%" height="39px"&gt;3&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&lt;P&gt;GW 3&lt;/P&gt;&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;884&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;854&lt;/TD&gt;&lt;TD width="20%" height="39px"&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a table that contains a history of recorded values at those locations listed above. (Table 2)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Table 2:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Location_ID&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Date&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="24px"&gt;Recorded_Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;&lt;P&gt;GW 1&lt;/P&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;&lt;P&gt;01/06/2021&lt;/P&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;&lt;P&gt;867.3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="39px"&gt;&lt;P&gt;GW 2&lt;/P&gt;&lt;/TD&gt;&lt;TD height="39px"&gt;01/06/2021&lt;/TD&gt;&lt;TD height="39px"&gt;894.1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;&lt;P&gt;GW 3&lt;/P&gt;&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;01/06/2021&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="39px"&gt;843.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;GW 1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;05/06/2021&lt;/TD&gt;&lt;TD&gt;862.4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to create a relationship between these two tables using the Location_ID as the Primary Key, using a one to many cardinality.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to achieve is to "join" the most recent value in the Recorded_Value column of Table 2 into the Current_Value column in Table 1 for each unique monitoring location (Location_ID). Furthermore, I need to ensure that the Recorded_Value (from Table 2) is within the upper and lower limits (from table 1).&lt;BR /&gt;&lt;BR /&gt;I'm thinking that I might be able to use a definition query (specifically using SQL) to achieve this.&lt;BR /&gt;Is this possible? If so, what would be the syntax to use a value from a related table in a definition query? Or is there an alternative way that I can achieve this?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 06:13:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-queries-on-related-tables/m-p/1072452#M42496</guid>
      <dc:creator>Nic_Pickering</dc:creator>
      <dc:date>2021-06-25T06:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Definition queries on related tables</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-queries-on-related-tables/m-p/1073103#M42572</link>
      <description>&lt;P&gt;There are a few possibilities, depending on what you're working with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have an Enterprise geodatabase, showing the latest record is really easy: Create a query layer (stored in the map document) or a database view (stored in the database) with the follwing SQL:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;SELECT t1.*, t2.*
FROM Table1 t1
INNER JOIN (
  SELECT Location_ID, MAX(Date) MaxDate
  FROM Table2
  GROUP BY Location_ID
) MaxDates
ON t1.Location_ID = MaxDates.Location_ID
INNER JOIN Table2 t2
ON MaxDates.Location_ID = t2.Location_ID AND MaxDates.MaxDate = t2.Date&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Both tools can be found in the DataManagement toolbox in the toolset "Layers and Table Views". However, making sure that the record is within the boundaries would be more complcated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you work in ArcGIS Pro, you can use Attribute Rules.&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.7/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/2.7/help/data/geodatabases/overview/an-overview-of-attribute-rules.htm&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Constraint Rule
// Table 2
// Triggers: Insert, Update
// Rejects the edit if the Recorded_Value is not within the upper and lower limits defined in Table 1

// load table 1
var tbl_1 = FeatureSetByName($datastore, "Table1", "*", false)

// filter table 1 by Location_ID
var loc_id = $feature.Location_ID
var loc = First(Filter(tbl_1, "Location_ID = @loc_id"))

// test if value falls within bounds, return true or false
var val = $feature.Recorded_Value
if(val &amp;gt;= loc.Lower_Limit_m &amp;amp;&amp;amp; val &amp;lt;= loc.Upper_Limit_m) {
  return true
}
return false&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Rule
// Table 2
// field: Recorded_Value
// Triggers: Insert
// If you add a new record to Table 2, the Recorded_Value will be written into Table1.CurrentValue_m
// This assumes that the record you add is actually the latest one!

// load table 1 and get the globalID of the location
var loc_id = $feature.LocationID
var g_id = First(Filter(FeatureSetByName($datastore, "Table1", ["Location_ID", "GlobalID"], false), "Location_ID = @loc_id")).GlobalID

// write the Rcorded_Value into Table1.Current_Value_m
return {
  "result": $feature.Recorded_Value,
  "edit": [
    {
      "className": "Table1",
      "updates": [
        {"globalID": g_id, "attributes": {"Current_Value_m": $feature.Recorded_Value}},
      ]
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If none of that works for you, you can use a Python script, but you'd have to manually run it every time you insert new records.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jun 2021 07:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-queries-on-related-tables/m-p/1073103#M42572</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-06-28T07:42:47Z</dc:date>
    </item>
  </channel>
</rss>

