Select Layer By Attribute (Data Management) |
|
Release 9.2
Last modified November 29, 2010 |
![]() ![]() ![]() Print all topics in : "Tools" |
Creates, updates, or removes a selection on the layer or table view using an attribute query.
Usage tips
The input must be a feature layer or a table view. It cannot be a feature class or table.
This tool is not limited to working in ArcMap; it works on layers and table views in ArcCatalog and in scripts. The Make Feature Layer tool makes a layer for a feature class, and the Make Table View tool does the equivalent for a table.
If an extent or a definition query is present on the input layer or table view, only those features or rows that match the extent and/or definition query will be available to be selected.
The Get Count tool returns the number of features selected by the tool.
For details on the syntax for the Expression parameter see: Building an SQL Expression or SQL Reference.
The following environment settings affect this tool: workspace, scratch workspace, Extent, M Domain, Configuration keyword, Coordinate system, Output has M values, Output spatial grid, Output has Z values, Default Z value, Output XY domain, and Output Z domain.
Command line syntax
An overview of the Command Line window
SelectLayerByAttribute_management <in_layer_or_view> {NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION | CLEAR_SELECTION} {where_clause}
Parameter | Explanation | Data Type |
<in_layer_or_view> |
The feature layer or table view to which the selection will be applied. This can be a layer or table in ArcMap or a layer or table view created by Make Layer or Make Table View in ArcCatalog or in a script. |
Table View |
{NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION | CLEAR_SELECTION} |
Determines how the selection will be applied and what to do if a selection already exists.
|
String |
{where_clause} |
An SQL expression used to select a subset of records. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, coverages, dBASE or INFO tables, enclose field names in double quotes: "MY_FIELD" If you're querying personal geodatabases, enclose fields in square brackets: [MY_FIELD]. For more information on SQL syntax and how it differs between data sources, see SQL Reference. |
SQL Expression |
SelectLayerByAttribute states NEW_SELECTION " [NAME] = 'California' "
Scripting syntax
About getting started with writing geoprocessing scripts
SelectLayerByAttribute_management (in_layer_or_view, selection_type, where_clause)
Parameter | Explanation | Data Type |
in_layer_or_view (Required) |
The feature layer or table view to which the selection will be applied. This can be a layer or table in ArcMap or a layer or table view created by Make Layer or Make Table View in ArcCatalog or in a script. |
Table View |
selection_type (Optional) |
Determines how the selection will be applied and what to do if a selection already exists.
|
String |
where_clause (Optional) |
An SQL expression used to select a subset of records. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, coverages, dBASE or INFO tables, enclose field names in double quotes: "MY_FIELD" If you're querying personal geodatabases, enclose fields in square brackets: [MY_FIELD]. For more information on SQL syntax and how it differs between data sources, see SQL Reference. |
SQL Expression |
# ExtactFeaturesByLocationAndAttribute.py # Description: Extract features to a new feature class based on a Location and an attribute query # Requirements: Python and the Python win32all extension # Author: ESRI # Data 1/1/2004 # Create the Geoprocessor import arcgisscripting gp = arcgisscripting.create() # Put in error trapping in case an error occurs when running tool try: # Make a layer from the feature class gp.MakeFeatureLayer("c:/mexico.mdb/cities","lyr") # Select all cities which overlap the chihuahua polygon gp.SelectLayerByLocation("lyr", "intersect", "c:/mexico.mdb/chihuahua", 0, "new_selection") # Within the selection (done above) further select only those cities which have a population > 10,000 gp.SelectLayerByAttribute("lyr", "SUBSET_SELECTION", " [population] > 10000 ") # Write the selected features to a new featureclass gp.CopyFeatures("lyr", "c:/mexico.mdb/chihuahua_10000plus") except: # If an error occurred print the message to the screen print gp.GetMessages()