<?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: MAX Date GROUP BY id in Model Builder in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/max-date-group-by-id-in-model-builder/m-p/1066543#M7236</link>
    <description>&lt;P&gt;I see the same results. Works fine for other numeric fields though. Doesn't work for date. Same as you, I'm seeing the duplicates as if it didn't Group on the ID field and then grab the most recent date. SQL Server 2017, ArcGIS SDE 10.7.1 and then trying this syntax straight from the Help on an ArcMap 10.7.1 definition query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Workaround - I resorted to making it a view in SSMS as a solution and it works beautifully. For my purposes I just needed it as a layer to have on a service. So I then added the view to ArcMap. I deduce there is some limitation or bug in Esri's SQL implementation with dates? Maybe it will get implemented in a future update? That is all I can deduce, since it works great in native SQL as Justin nicely outlined.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Jun 2021 13:46:00 GMT</pubDate>
    <dc:creator>KevinMacLeodCAI</dc:creator>
    <dc:date>2021-06-11T13:46:00Z</dc:date>
    <item>
      <title>MAX Date GROUP BY id in Model Builder</title>
      <link>https://community.esri.com/t5/geodatabase-questions/max-date-group-by-id-in-model-builder/m-p/1008256#M6892</link>
      <description>&lt;P&gt;Version: ArcGIS Pro 2.6.3&lt;/P&gt;&lt;P&gt;Data: Enterprise SQL 2016&lt;/P&gt;&lt;P&gt;I have a table of parcel sales data, with ParcelID field (text type) as the parcel identifier and SaleDate (date type).&amp;nbsp; There are multiple rows for the same ParcelID value, each with a different SaleDate value.&amp;nbsp; I want a selectio of the records keeping only the latest date, within model builder (it's part of a larger process).&lt;/P&gt;&lt;P&gt;Based on the guidance here:&amp;nbsp;&lt;A href="https://support.esri.com/en/technical-article/000008936" target="_blank"&gt;https://support.esri.com/en/technical-article/000008936&lt;/A&gt;&amp;nbsp;I have the following in a Select Layer By Attribute or Table Select tool - both have the same results:&lt;/P&gt;&lt;P&gt;SaleDate IN (SELECT MAX(SaleDate) FROM countySL GROUP BY ParcelID)&lt;/P&gt;&lt;P&gt;I cannot get this to return the correct values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run this in SSMS and get exactly what I'd expect:&lt;/P&gt;&lt;P&gt;SELECT n.*&lt;BR /&gt;FROM [dbo].[COUNTYSL] n&lt;BR /&gt;INNER JOIN (&lt;BR /&gt;SELECT ParcelID, MAX(SaleDate) AS SaleDate&lt;BR /&gt;FROM [dbo].[COUNTYSL] GROUP BY ParcelID&lt;BR /&gt;) AS MAX ON MAX.ParcelID = n.ParcelID AND MAX.SaleDate = n.SaleDate ORDER BY ParcelID;&lt;BR /&gt;GO&lt;/P&gt;&lt;P&gt;I had originally built everything around FGDB, but moved to Enterprise SQL to use GROUP BY functionality.&amp;nbsp; Is there something special with the date format?&lt;/P&gt;&lt;P&gt;In SSMS, this is what the countySL data looks like:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Source countySL table" style="width: 418px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1827i4A70B564F2ED4FD1/image-size/large?v=v2&amp;amp;px=999" role="button" title="parcel_countySL.PNG" alt="Source countySL table" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Source countySL table&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And if I run the query below I get what I need:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="functional query in SSMS" style="width: 703px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1828iA4A9D352F9D673F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="parcelGroupBy.PNG" alt="functional query in SSMS" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;functional query in SSMS&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But in ArcGIS Pro model builder, if I use the query below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SQL in Model Builder" style="width: 372px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1829i656CADAA56228145/image-size/large?v=v2&amp;amp;px=999" role="button" title="parcel_TableSelect.PNG" alt="SQL in Model Builder" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;SQL in Model Builder&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I get this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Table Select results" style="width: 143px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1830i9A0027BDB73A1DE0/image-size/large?v=v2&amp;amp;px=999" role="button" title="parcelTableSelectResult.PNG" alt="Table Select results" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Table Select results&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I've attempted using the Select Layer By Attribute tool as well, and messed with the 'Invert Where Clause' and attempted to switch selection from the source table, but it doesn't work either.&amp;nbsp; What am I missing?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 20:51:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/max-date-group-by-id-in-model-builder/m-p/1008256#M6892</guid>
      <dc:creator>JustinWolff</dc:creator>
      <dc:date>2020-12-09T20:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: MAX Date GROUP BY id in Model Builder</title>
      <link>https://community.esri.com/t5/geodatabase-questions/max-date-group-by-id-in-model-builder/m-p/1066543#M7236</link>
      <description>&lt;P&gt;I see the same results. Works fine for other numeric fields though. Doesn't work for date. Same as you, I'm seeing the duplicates as if it didn't Group on the ID field and then grab the most recent date. SQL Server 2017, ArcGIS SDE 10.7.1 and then trying this syntax straight from the Help on an ArcMap 10.7.1 definition query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Workaround - I resorted to making it a view in SSMS as a solution and it works beautifully. For my purposes I just needed it as a layer to have on a service. So I then added the view to ArcMap. I deduce there is some limitation or bug in Esri's SQL implementation with dates? Maybe it will get implemented in a future update? That is all I can deduce, since it works great in native SQL as Justin nicely outlined.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 13:46:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/max-date-group-by-id-in-model-builder/m-p/1066543#M7236</guid>
      <dc:creator>KevinMacLeodCAI</dc:creator>
      <dc:date>2021-06-11T13:46:00Z</dc:date>
    </item>
  </channel>
</rss>

