I am trying to use the Select_analysis tool to select the minimum value from the input geodatabase feature class and export that to a new feature class via a where clause. I think I'm getting tripped up on the SQL syntax.

Relevant code:


arcpy.Select_analysis(input, output, sql)

My input and output are defined path variables elsewhere in the code.

I am using ArcGIS Desktop 10.6.

closed as off-topic by PolyGeo Jul 21 '18 at 20:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to GIS SE. As a new user, please take the Tour. Please Edit the question to specify the type of geodstabase, and if enterprise, which RDBMS. Complete details in the body of the question aids in answer generation. – Vince Jul 21 '18 at 18:34
  • 2
    What happens when you try to run the code that you have presented? – PolyGeo Jul 21 '18 at 20:17

At first the exception is that this form of select statement does only work on database formats. If you have a shapefile it will not work at all. The syntax you need here is a bit different as in the select by attributes ArcMap needs a subquery for min(). The following should work. The delimiters in ArcMap depend on the format as well. You might need to use other than " around your field names(" is for FileGeodatabase).

sql = """"your_field" = (SELECT MIN( "your_field" ) from "your_table")"""

Not the answer you're looking for? Browse other questions tagged or ask your own question.