<?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 Using SQL to &amp;quot;Select by Attributes&amp;quot; comparing fields... in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777800#M1429</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to write a simple SQL query that just isn't working. I have two fields in my file geodatabase layer (ArcGIS Pro 2.3) and I want&amp;nbsp;to select the records that match my simple SQL query of:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="435963" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/435963_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;written out to LEFT(Layer,3) = OWNERSHIP_NUMBER&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I get an error saying that "The SQL expression has invalid syntax".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I must be doing it wrong somewhere but I don't know where. These are both FIELDS and not RECORDS, so that likely makes a difference in how my syntax is supposed to be written.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking up this article:&amp;nbsp;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" title="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it says "&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #4c4c4c; background-color: #ffffff; margin-bottom: 1.55rem;"&gt;String functions can be used to format strings. For instance, the LEFT function would return a certain number of characters starting on the left of the string. In this example, the query would return all states starting with the letter A:&lt;/P&gt;&lt;PRE style="color: #4c4c4c; background-color: #ffffff; font-size: 17px; margin-bottom: 1.55rem;"&gt;LEFT(STATE_NAME,1) = 'A'&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, it makes me think my syntax is mostly right since both of my fields are strings. Any advice on making my SQL query syntax work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jan 2019 17:00:52 GMT</pubDate>
    <dc:creator>AdrianWelsh</dc:creator>
    <dc:date>2019-01-28T17:00:52Z</dc:date>
    <item>
      <title>Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777800#M1429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to write a simple SQL query that just isn't working. I have two fields in my file geodatabase layer (ArcGIS Pro 2.3) and I want&amp;nbsp;to select the records that match my simple SQL query of:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="435963" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/435963_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;written out to LEFT(Layer,3) = OWNERSHIP_NUMBER&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I get an error saying that "The SQL expression has invalid syntax".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I must be doing it wrong somewhere but I don't know where. These are both FIELDS and not RECORDS, so that likely makes a difference in how my syntax is supposed to be written.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking up this article:&amp;nbsp;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" title="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it says "&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #4c4c4c; background-color: #ffffff; margin-bottom: 1.55rem;"&gt;String functions can be used to format strings. For instance, the LEFT function would return a certain number of characters starting on the left of the string. In this example, the query would return all states starting with the letter A:&lt;/P&gt;&lt;PRE style="color: #4c4c4c; background-color: #ffffff; font-size: 17px; margin-bottom: 1.55rem;"&gt;LEFT(STATE_NAME,1) = 'A'&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, it makes me think my syntax is mostly right since both of my fields are strings. Any advice on making my SQL query syntax work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 17:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777800#M1429</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2019-01-28T17:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777801#M1430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My initial reaction is that it should be written as&amp;nbsp;field = some value, therefore:&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;OWNERSHIP_NUMBER = LEFT(Layer,3)&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is assuming that ownership number is text, as Left is a text function.&amp;nbsp; It might be helpful if you could share an example of ownership_number and layer, if you are still having problems.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 17:24:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777801#M1430</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-01-28T17:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777802#M1431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmmm, that gave me the same error.&lt;/P&gt;&lt;P&gt;Details: both fields are text fields and contain numbers.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ownership_number are normally 3 digit numbers that sometimes contain a letter. Examples are 100, 101, 102, 102B, etc.&lt;/P&gt;&lt;P&gt;Layer has the same three digit numbers with additional info usually in the case of colons. So, examples: 100:E 100:PUE, 101:ST, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just want this SQL query to work so I can modify it to narrow down my search, etc. (finding where these numbers do not match). Thanks for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Bonus, does it matter that one text field is 255 characters long and the other is 8000 characters?)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 17:30:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777802#M1431</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2019-01-28T17:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777803#M1432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think since you are using a file geodatabase you might need to use something like (you'll&amp;nbsp;want to make sure both sides are a string of 3 characters):&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;SUBSTRING("OWNERSHIP_NUMBER" FROM 1 FOR 3) = SUBSTRING("Layer" FROM 1 FOR 3)&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(This from an old thread: &lt;A _jive_internal="true" href="https://community.esri.com/message/287022"&gt;Definition query SQL won't accept Left() Function&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;And according to &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm"&gt;SQL reference for query expressions used in ArcGIS&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;All SQL used by the file geodatabase is based on the SQL-92 standard.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 19:29:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777803#M1432</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-01-28T19:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777804#M1433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Randy, I believe your comment is correct, at least in terms of making it work.&amp;nbsp; Adrian's confusion originates from 2 facts:&amp;nbsp; 1) "LEFT" is commonly implemented in DBMSs, and 2) Esri's own documentation clearly states "LEFT" should work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 20:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777804#M1433</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-01-28T20:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777805#M1434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At one time, I would swear that I used "LEFT" with a&amp;nbsp;file geodatabase.&amp;nbsp;&amp;nbsp;But it wasn't working today ... which I attributed to just being a Monday! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 20:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777805#M1434</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-01-28T20:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777806#M1435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just tried in Pro 2.3, 10.7 Prerelease, and 10.3.1; and all of them generated the same invalid syntax error.&amp;nbsp; Maybe 9.x?&amp;nbsp; &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 21:30:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777806#M1435</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-01-28T21:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777807#M1436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for sharing that Randy. I'll have to check it out tomorrow to see if it will work. I'll report back here!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2019 21:44:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777807#M1436</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2019-01-28T21:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777808#M1437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Randy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nice digging on that old thread. Your suggestion mostly worked! I don't know why it didn't all-the-way work but that is on my end.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(my example is, after the query of&amp;nbsp;&lt;/P&gt;&lt;PRE class="line-numbers language-markup"&gt;&lt;CODE&gt;SUBSTRING("Layer" FROM 1 FOR 3) &amp;lt;&amp;gt; SUBSTRING("OWNERSHIP_NUMBER" FROM 1 FOR 3)&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;wherever I have null values, these were not part of my selection - so, Layer would = 144B and OWNERSHIP_NUMBER would = &amp;lt;null&amp;gt;, and these are clearly different, this record was not selected. This is true when I flip-flop the query as well.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Either way, this gets me past my initial question of why LEFT didn't work. Thanks again!&lt;/P&gt;&lt;P&gt;(maybe Esri should change that documentation........)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2019 16:30:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777808#M1437</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2019-01-29T16:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777809#M1438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The presence of NULL introduces three-value logic into SQL comparison operators.&amp;nbsp; What you are seeing regarding your comparisons with NULL is expected.&amp;nbsp; It might be worth checking out &lt;A class="link-titled" href="https://modern-sql.com/concept/three-valued-logic" title="https://modern-sql.com/concept/three-valued-logic"&gt;Modern SQL: Three-Valued Logic (3VL)&amp;nbsp;— Purpose, Benefits and Special Cases&lt;/A&gt;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2019 19:30:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777809#M1438</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-01-29T19:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777810#M1439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And the page referenced also says:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;A Lot Has Changed Since SQL-92&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And so it has. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2019 20:15:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777810#M1439</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-01-29T20:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL to "Select by Attributes" comparing fields...</title>
      <link>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777811#M1440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Geeze, you're right! This is a great segment from that article:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #4b4b4b; background-color: #fcfcfc; margin: 0px 0px 1em;"&gt;The result of each of the following comparisons is therefore&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #242424;"&gt;&lt;EM&gt;unknown&lt;/EM&gt;&lt;/SPAN&gt;:&lt;A class="" href="https://modern-sql.com/concept/three-valued-logic#footnote-0" style="color: #007434; text-decoration: none; font-size: 0.7em;" title="SQL:2016-2: §8.2, General Rule 1a" rel="nofollow noopener noreferrer" target="_blank"&gt;0&lt;/A&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;NULL = 1 
NULL &amp;lt;&amp;gt; 1 
NULL &amp;gt; 1 
NULL = NULL&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #4b4b4b; background-color: #fcfcfc; margin: 0px 0px 1em;"&gt;Nothing&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #242424;"&gt;&lt;EM&gt;equals&lt;/EM&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;null&lt;/CODE&gt;. Not even&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;null&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;equals&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;null&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;because each&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;null&amp;nbsp;&lt;/CODE&gt;could be different.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Haha, oh null. What a conundrum&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:45:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/using-sql-to-quot-select-by-attributes-quot/m-p/777811#M1440</guid>
      <dc:creator>AdrianWelsh</dc:creator>
      <dc:date>2021-12-12T08:45:06Z</dc:date>
    </item>
  </channel>
</rss>

