Table Select (Analysis)
Summary
Selects table records matching a Structured Query Language (SQL) expression and writes them to an output table.
Usage
-
The input can be an INFO, dBASE, or geodatabase table, a feature class, table view, or VPF dataset.
-
The Expression parameter can be created with the Query Builder or simply typed in. For details on the expression syntax see Building an SQL Expression or SQL Reference.
-
If a table view is used for Input Table and no expression is entered, only the selected records are written to the output table. If a table view is used for input table and an expression is entered, the expression is only executed against the selected records, and the expression-based subset of the selected set is written to the output table.
If you want to create a table from the table view's selected set of records, use the Copy Rows (management) tool.
Syntax
Parameter | Explanation | Data Type |
in_table |
The table whose records matching the specified expression will be written to the output table. | Table View; Raster Layer |
out_table |
The output table containing records from the input table that match the specified expression. | Table |
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, or 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] In Python, strings are enclosed in matching single or double quotes. To create a string that contains quotes (as is common with a WHERE clause in SQL expressions), you can escape the quotes (using a backslash) or triple quote the string. For example, if the intended WHERE clause is "CITY_NAME" = 'Chicago' you could enclose the entire string in double quotes, then escape the interior double quotes like this: " \"CITY_NAME\" = 'Chicago' " Or you could enclose the entire string in single quotes, then escape the interior single quotes like this: ' "CITY_NAME" = \'Chicago\' ' Or you could enclose the entire string in triple quotes without escaping: """ "CITY_NAME" = 'Chicago' """ For more information on SQL syntax and how it differs between data sources, see the help topic SQL reference for query expressions used in ArcGIS. | SQL Expression |
Code Sample
The following Python Window script demonstrates how to use the Table Select function in immediate mode.
import arcpy from arcpy import env env.workspace = "C:/data" arcpy.TableSelect_analysis("majorrds.shp", "C:/output/majorrdsCl4.shp", '"CLASS" = \'4\'')
The following Python script demonstrates how to use the Table Select function in a stand-alone script.
# Name: TableSelect_Example2.py # Description: Selct class4 roads from the major roads gnatcatcher habitat study area # Author: ESRI # Import system modules import arcpy from arcpy import env # Set workspace env.workspace = "C:/data" # Set local variables in_features = "majorrds.shp" out_feature_class = "C:/output/majorrdsCl4.shp" where_clause = '"CLASS" = \'4\'' # Execute TableSelect arcpy.TableSelect_analysis(in_features, out_feature_class, where_clause)