<?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>idea Clarify the docs: Correlated subqueries not supported in FGDB SQL expressions in Data Management Ideas</title>
    <link>https://community.esri.com/t5/data-management-ideas/clarify-the-docs-correlated-subqueries-not/idi-p/1239429</link>
    <description>&lt;P&gt;Add a line to the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" target="_self"&gt;SQL Expression docs&lt;/A&gt; that clearly states:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;EM&gt;Correlated subqueries are &lt;U&gt;not&lt;/U&gt; supported in file geodatabase SQL expressions&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A database performs a &lt;/SPAN&gt;&lt;SPAN class=""&gt;correlated subquery&lt;/SPAN&gt;&lt;SPAN&gt; when a nested subquery references a column from a table in a parent statement one or more levels above the subquery.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Since correlated subqueries aren’t supported, SQL expressions on file geodatabases can’t do things like get the &lt;I&gt;greatest 1 per group&lt;/I&gt;, and other similar requirements:&lt;/P&gt;&lt;PRE&gt;NOT EXISTS (
        SELECT *
        FROM road_insp r2
        WHERE r2.asset_id = road_insp.asset_id AND r2.date_ &amp;gt; road_insp.date_
       )&lt;BR /&gt;--Demo:  &lt;A href="https://dbfiddle.uk/gSGjLTCW" target="_blank" rel="noopener"&gt;https://dbfiddle.uk/gSGjLTCW&lt;/A&gt; &lt;/PRE&gt;&lt;P&gt;The above file geodatabase SQL expression would select all rows in&amp;nbsp;the table, which would be incorrect.&lt;BR /&gt;It’s important to note that the query fails &lt;I&gt;silently&lt;/I&gt;, producing incorrect results, rather than throwing an error. Therefore, correlated subqueries should be avoided in file geodatabase SQL expressions to avoid producing misleading results.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;SPAN&gt;Related:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/gis-blog/when-exists-doesn-t-file-geodatabases-and/ba-p/896574" target="_self"&gt;When EXISTS Doesn't: File Geodatabases and Correlated Subqueries&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://gis.stackexchange.com/questions/446891/file-geodatabase-sql-expression-to-get-greatest-n-per-group" target="_self"&gt;File Geodatabase SQL expression to get greatest n per group&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://stackoverflow.com/questions/74735554/select-greatest-n-per-group-using-exists" target="_self"&gt;Select greatest 1 per group using EXISTS&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/support-correlated-subqueries-in-file-geodatabase/idi-p/1238551" target="_self"&gt;Support correlated subqueries in file geodatabase SQL expressions&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Tue, 16 Jan 2024 08:47:04 GMT</pubDate>
    <dc:creator>Bud</dc:creator>
    <dc:date>2024-01-16T08:47:04Z</dc:date>
    <item>
      <title>Clarify the docs: Correlated subqueries not supported in FGDB SQL expressions</title>
      <link>https://community.esri.com/t5/data-management-ideas/clarify-the-docs-correlated-subqueries-not/idi-p/1239429</link>
      <description>&lt;P&gt;Add a line to the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" target="_self"&gt;SQL Expression docs&lt;/A&gt; that clearly states:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;EM&gt;Correlated subqueries are &lt;U&gt;not&lt;/U&gt; supported in file geodatabase SQL expressions&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;A database performs a &lt;/SPAN&gt;&lt;SPAN class=""&gt;correlated subquery&lt;/SPAN&gt;&lt;SPAN&gt; when a nested subquery references a column from a table in a parent statement one or more levels above the subquery.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Since correlated subqueries aren’t supported, SQL expressions on file geodatabases can’t do things like get the &lt;I&gt;greatest 1 per group&lt;/I&gt;, and other similar requirements:&lt;/P&gt;&lt;PRE&gt;NOT EXISTS (
        SELECT *
        FROM road_insp r2
        WHERE r2.asset_id = road_insp.asset_id AND r2.date_ &amp;gt; road_insp.date_
       )&lt;BR /&gt;--Demo:  &lt;A href="https://dbfiddle.uk/gSGjLTCW" target="_blank" rel="noopener"&gt;https://dbfiddle.uk/gSGjLTCW&lt;/A&gt; &lt;/PRE&gt;&lt;P&gt;The above file geodatabase SQL expression would select all rows in&amp;nbsp;the table, which would be incorrect.&lt;BR /&gt;It’s important to note that the query fails &lt;I&gt;silently&lt;/I&gt;, producing incorrect results, rather than throwing an error. Therefore, correlated subqueries should be avoided in file geodatabase SQL expressions to avoid producing misleading results.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;SPAN&gt;Related:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/gis-blog/when-exists-doesn-t-file-geodatabases-and/ba-p/896574" target="_self"&gt;When EXISTS Doesn't: File Geodatabases and Correlated Subqueries&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://gis.stackexchange.com/questions/446891/file-geodatabase-sql-expression-to-get-greatest-n-per-group" target="_self"&gt;File Geodatabase SQL expression to get greatest n per group&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://stackoverflow.com/questions/74735554/select-greatest-n-per-group-using-exists" target="_self"&gt;Select greatest 1 per group using EXISTS&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/support-correlated-subqueries-in-file-geodatabase/idi-p/1238551" target="_self"&gt;Support correlated subqueries in file geodatabase SQL expressions&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 16 Jan 2024 08:47:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-ideas/clarify-the-docs-correlated-subqueries-not/idi-p/1239429</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2024-01-16T08:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Clarify the docs: Correlated subqueries not supported in FGDB SQL expressions</title>
      <link>https://community.esri.com/t5/data-management-ideas/clarify-the-docs-correlated-subqueries-not/idc-p/1262212#M2106</link>
      <description>&lt;P&gt;BUG-000156143 - An SQL query containing the EXISTS predicate validates successfully but returns incorrect results from a file geodatabase.&lt;BR /&gt;&lt;BR /&gt;ENH-000156158 -&amp;nbsp;Raise exception when using unsupported SQL expressions in file geodatabases.&lt;/P&gt;&lt;P&gt;Esri Canada Case 03264937 -&amp;nbsp;Exception not raised when unsupported FGDB SQL used (correlated subquery)&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 23:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-ideas/clarify-the-docs-correlated-subqueries-not/idc-p/1262212#M2106</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-02-27T23:31:23Z</dc:date>
    </item>
  </channel>
</rss>

