<?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: arcpy.SelectLayerByAttribute returns a subset of the &amp;quot;truth&amp;quot; in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718639#M23802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you kimo. I had forgotten about 'in' as an SQL operator (i'm a recovering SAS programmer). This makes the code much more clear.&amp;nbsp; Using a new select, then select from.. as you suggest simplifies things as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It appears that what I was missing is that the arguments to the arcpy function all have to be within a single quoted string.&amp;nbsp; The following line returns the 14 expected values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management ("view", "NEW_SELECTION", """ "SP10" in ('WS','BS','JP','BF','TL') and&amp;nbsp; "SP11" in ('TA','BP','WB','WE','GA','MM') """)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Oct 2011 14:21:49 GMT</pubDate>
    <dc:creator>LaneGelhorn</dc:creator>
    <dc:date>2011-10-11T14:21:49Z</dc:date>
    <item>
      <title>arcpy.SelectLayerByAttribute returns a subset of the &amp;quot;truth&amp;quot;</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718637#M23800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to write a python script which selects a number of cases from an attribute table (table view within a file geodatabase) to allow further processing but am getting curious results. It seems as though the query stops once it fullfills the latest condition, regardless of preceeding conditions.&amp;nbsp; For example: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management ("view", "NEW_SELECTION",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; (""" "SP10" = 'WS' """ or """ "SP10" = 'BS' """ or """ "SP10" = 'JP' """&amp;nbsp; or """ "SP10" = 'BF' """ or&amp;nbsp; """ "SP10" = 'TL' """)&amp;nbsp; and (""" "SP11" = 'TA' """ or """ "SP11" = 'BP' """ or """ "SP11" = 'WB' """ or """ "SP11" = 'WE' """ or """ "SP11" = 'MM' """ or """ "SP11" = 'GA' """ ))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;will return only those records where SP11 = TA, regardless of the value of SP10.&amp;nbsp; In this case 13 records are returned. I can find those same 13 records from&amp;nbsp; using the where condition "SP11" = 'TA'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in the ArcGIS select by attributes dialogue box. Placing the full set of conditions in the select by attributes dialogue box I get a different set of 14 (correct) selected records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone have any advice for dealing with this? Others found similar results?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Oct 2011 21:44:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718637#M23800</guid>
      <dc:creator>LaneGelhorn</dc:creator>
      <dc:date>2011-10-07T21:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.SelectLayerByAttribute returns a subset of the "truth"</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718638#M23801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use a simpler SQL expression like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sql expr = "SP10 in ('WS','BS','AP') AND SP11 in ('MM','GA')"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your logic is hard to follow, make subsets and select multiple times using the 'SELECT_FROM...' options.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Check each sql query produces the desired values by running it interactively in ArcMap table selections.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also get rid of all the extra double quotes. If you use valid field names you don't ever need to quote them. (ie start with a character, no spaces or punctuation characters, no reserved words)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[You do need square brackets for MS Access, but that doesn't count]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Oct 2011 02:16:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718638#M23801</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-10-09T02:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.SelectLayerByAttribute returns a subset of the "truth"</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718639#M23802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you kimo. I had forgotten about 'in' as an SQL operator (i'm a recovering SAS programmer). This makes the code much more clear.&amp;nbsp; Using a new select, then select from.. as you suggest simplifies things as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It appears that what I was missing is that the arguments to the arcpy function all have to be within a single quoted string.&amp;nbsp; The following line returns the 14 expected values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management ("view", "NEW_SELECTION", """ "SP10" in ('WS','BS','JP','BF','TL') and&amp;nbsp; "SP11" in ('TA','BP','WB','WE','GA','MM') """)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 14:21:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-selectlayerbyattribute-returns-a-subset-of/m-p/718639#M23802</guid>
      <dc:creator>LaneGelhorn</dc:creator>
      <dc:date>2011-10-11T14:21:49Z</dc:date>
    </item>
  </channel>
</rss>

