<?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: Can a SQL expression be created to select the five ( 5 ) greatest and five ( 5 ) least values of a parameter? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96530#M3328</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Ted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using ArcGIS, although I could probably figure out how to implement your solution using Access.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Oct 2014 18:04:37 GMT</pubDate>
    <dc:creator>Michael_StanleyGallisdorfer</dc:creator>
    <dc:date>2014-10-23T18:04:37Z</dc:date>
    <item>
      <title>Can a SQL expression be created to select the five ( 5 ) greatest and five ( 5 ) least values of a parameter?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96528#M3326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wish to select only the five ( 5 ) greatest and five ( 5 ) least values of a parameter ( elevation ) for several sets of over 1000 points. Batch selecting requires that SQL expressions for the desired greatest and least unique values be identified manually, which is very time consuming.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Background:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Five ( 5 ) greatest and least elevation values should be selected from a very large set of elevation points. Setting-up a batch selection with SQL expressions conforming to unique point elevation values consumes much time, slowing data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Goal:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A SQL expression or tool that allows points with the specified attributes to be selected and exported to a new shapefile. Conceptually, the process might be considered according to the following steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Sort point elevations, ascending or descending values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Identify the greatest and least elevation values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Select the greatest, and second-fifth greatest, and the least through fifth-least elevations&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. Export the selected points to a new point shapefile&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Logically, the query could be expressed in the following way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. The greatest point elevation is greater than all other point elevation values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. The second greatest point elevation value is less than the point identified in 1, above, but greater than all other values, and so on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 16:43:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96528#M3326</guid>
      <dc:creator>Michael_StanleyGallisdorfer</dc:creator>
      <dc:date>2014-10-23T16:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can a SQL expression be created to select the five ( 5 ) greatest and five ( 5 ) least values of a parameter?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96529#M3327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The SQL expression to be used would be dependant upon your database.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A SQL Server way of doing would follow this type of logic:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14140850956756696" jivemacro_uid="_14140850956756696"&gt;
&lt;P&gt;Select Top 5 Min(ElevationFieldName) Elevation, ElevationID from TablewithElevation&lt;/P&gt;
&lt;P&gt;Union All&lt;/P&gt;
&lt;P&gt;Select Top 5 Max(ElevationFieldName) Elevation, ElevationID from TablewithElevation&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Note that the number of fields and basic data types must be the same in both select statements.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Oracle does not have a Top function and would have to use embedded select statments with a where clause limiting the rows along with the Union.&amp;nbsp; (A bit more complicated -- plenty of examples on google)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Access would be similar to SQL Sever&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what comes immediately to mind!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 17:30:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96529#M3327</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2014-10-23T17:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can a SQL expression be created to select the five ( 5 ) greatest and five ( 5 ) least values of a parameter?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96530#M3328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Ted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using ArcGIS, although I could probably figure out how to implement your solution using Access.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 18:04:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96530#M3328</guid>
      <dc:creator>Michael_StanleyGallisdorfer</dc:creator>
      <dc:date>2014-10-23T18:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can a SQL expression be created to select the five ( 5 ) greatest and five ( 5 ) least values of a parameter?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96531#M3329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was my intent ... so give you a starting point.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One more tip... when using access to develop your queries I would do it in multiple phases so that any errors can be isolated quickly...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem set up... if there is no unique unchangeable ID in your GIS data I would create a field in the elevation data (GIS) that is unique and unchangeable.&amp;nbsp; This field will be used to link the developed sql queries back to the GIS so they may be seen in ArcGIS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MS Access:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a query selecting the Top 5 (individual query) from the GIS data&amp;nbsp; -- save it in access&lt;/LI&gt;&lt;LI&gt;Create a query selecting the Bottom 5&amp;nbsp; (individual query) from the GIS data&amp;nbsp; -- save it in access&lt;/LI&gt;&lt;LI&gt;Make sure the above query includes all the same fields including the unchangeable ID field.&lt;/LI&gt;&lt;LI&gt;Create a Union query combining #1 and #2 -- save it in access &lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To see the results in ArcGIS, Add the Union Query to the ArcGIS map as a datatable (If you did not know, you can add a named access query to the ArcGIS Map).&amp;nbsp; Join the elevation gis data with the unique unchangeable ID with that same ID in the union query with matching ID's only.&amp;nbsp; The result map should now only show the Top 5 and Bottom 5 results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is helpful,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ted&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2014 14:25:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/can-a-sql-expression-be-created-to-select-the-five/m-p/96531#M3329</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2014-10-24T14:25:02Z</dc:date>
    </item>
  </channel>
</rss>

