<?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: SQL error when creating a Query Layer in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028688#M2022</link>
    <description>&lt;P&gt;I think you will need to use&lt;A href="https://www.sqlservertutorial.org/sql-server-alias/" target="_self"&gt; table name aliases&lt;/A&gt; for the two join sections to avoid this. I see it is a self-join, but that doesn't make a difference. This will also make your query much more readable, as you don't need to repeat the whole long concatenation of "GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION", but can instead refer to the aliases. The error message suggests SQL Server already attempted to add an alias automatically ('a.'), but since it is self joined table, likely used only the 'a' alias, and not a second one, e.g. 'b', for the table to join.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Feb 2021 19:52:52 GMT</pubDate>
    <dc:creator>MarcoBoeringa</dc:creator>
    <dc:date>2021-02-19T19:52:52Z</dc:date>
    <item>
      <title>SQL error when creating a Query Layer</title>
      <link>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028638#M2020</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to create a new Query Layer based on the following SQL Query.&amp;nbsp; In MS Access this query works, but in ArcMap I get an error about a duplicate field name.&amp;nbsp; Can anyone suggest a work-around for this??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my query:&lt;/P&gt;&lt;P&gt;SELECT * from&lt;/P&gt;&lt;P&gt;(SELECT GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.*&lt;BR /&gt;FROM GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION&lt;BR /&gt;WHERE (((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.DATEWORK) Is Null) AND ((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.HYDRANT_OPERATION)&amp;lt;&amp;gt;'OK')) OR (((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.DATEWORK) Is Null) AND ((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.OPERATING_NUT)&amp;lt;&amp;gt;'OK')) OR (((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.DATEWORK) Is Null) AND ((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.NOZZLE_CAPS)&amp;lt;&amp;gt;'OK')) OR (((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.DATEWORK) Is Null) AND ((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.FLANGES)&amp;lt;&amp;gt;'OK')) OR (((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.DATEWORK) Is Null) AND ((GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.WATER_IN_BARREL)='True'))) ALL_WR_Table&lt;/P&gt;&lt;P&gt;INNER JOIN&lt;/P&gt;&lt;P&gt;(SELECT Max(GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.INSP_DATE) AS MaxOfINSP_DATE, GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.FACILITYID&lt;BR /&gt;FROM GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION&lt;BR /&gt;GROUP BY GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION.FACILITYID) MOST_RECENT_Table&lt;/P&gt;&lt;P&gt;ON&lt;/P&gt;&lt;P&gt;(ALL_WR_Table.FACILITYID=MOST_RECENT_Table.FACILITYID) AND (ALL_WR_Table.INSP_DATE =MOST_RECENT_Table.MaxOfINSP_DATE)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the error message:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianBulla_0-1613758710384.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/6455i8D84BBD44800A81E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrianBulla_0-1613758710384.png" alt="BrianBulla_0-1613758710384.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 18:19:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028638#M2020</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2021-02-19T18:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: SQL error when creating a Query Layer</title>
      <link>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028688#M2022</link>
      <description>&lt;P&gt;I think you will need to use&lt;A href="https://www.sqlservertutorial.org/sql-server-alias/" target="_self"&gt; table name aliases&lt;/A&gt; for the two join sections to avoid this. I see it is a self-join, but that doesn't make a difference. This will also make your query much more readable, as you don't need to repeat the whole long concatenation of "GISWRKS1.works.INSPECTIONS_HYDRANT_INSPECTION", but can instead refer to the aliases. The error message suggests SQL Server already attempted to add an alias automatically ('a.'), but since it is self joined table, likely used only the 'a' alias, and not a second one, e.g. 'b', for the table to join.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 19:52:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028688#M2022</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2021-02-19T19:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: SQL error when creating a Query Layer</title>
      <link>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028727#M2023</link>
      <description>&lt;P&gt;Thanks Marco.&amp;nbsp; I actually just figured this out too.&amp;nbsp; Since the FACILITYID is coming from two different 'tables' I just needed to specify ALL_WR_Table.FACILITYID (as well as all the other fields).&lt;/P&gt;&lt;P&gt;Yes, I now realize that using an alias would be more helpful too!!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 20:56:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/sql-error-when-creating-a-query-layer/m-p/1028727#M2023</guid>
      <dc:creator>BrianBulla</dc:creator>
      <dc:date>2021-02-19T20:56:16Z</dc:date>
    </item>
  </channel>
</rss>

