Documente Academic
Documente Profesional
Documente Cultură
Structured Query Language (SQL) is a powerful language you use to define one or more criteria that
can consist of attributes, operators, and calculations. For example, imagine you have a map of
customers and want to find those who spent more than $50,000 with you last year and whose business
type is "Restaurant". You would select the customers with this expression: Sales > 50000 AND
.'Business_type = 'Restaurant
In ArcMap, you can select features by searching with a Structured Query Language (SQL) expression.
When you create an expression in the Select By Attributes dialog box, you create it in a version of SQL;
the one you use depends on the format of the data you're querying. You use ANSI SQL with shared
geodatabase data and Jet SQL with personal geodatabase data. These two versions of SQL are similar;
.however, each supports features and functions the other doesn't
When you query coverages, shapefiles, INFO tables, and dBASE tables, you use a limited version of
SQL that doesn't support functions or the many features of ANSI and Jet SQL. The following sections
show you how to build simple expressions. For information on how to build more complex expressions,
.see your SQL reference manual
Some special rules apply when building a SQL expression for joined layers and tables. For more
information, see the Knowledge Base article, How to properly format an SQL expression to make
.selections in joined layers and tables
Specifying fields
If you're querying ArcInfo coverages, shapefiles, INFO tables, or dBASE tables, enclose fields in double
:quotes
"AREA"
:If you're querying personal geodatabase data, enclose fields in square brackets
[AREA]
AREA
'California' = [STATE_NAME]
Strings are case-sensitive for coverages, shapefiles, INFO tables, dBASE tables, and shared
geodatabases. If you are unsure of case, use the operator LIKE, not '='. For example, "STATE_NAME"
= 'rhode island' will not find a feature with "Rhode Island" in its attribute record, but "STATE_NAME"
.LIKE 'rhode island' will
Strings are not case-sensitive for personal geodatabases. For example, [STATE_NAME] = 'rhode island'
.will select a feature with "Rhode Island" in its attribute record
If you are uncertain of spelling or just want to use a shorter string in your expression, use LIKE with
:wildcards. If you are querying a coverage, shapefile, INFO table, dBASE table, or shared geodatabase
.represents any one character and '%' any group of characters '_'
.represents any one character and '*' any group of characters '?'
This query will find Catherine Smith and Katherine Smith in a layer based on personal geodatabase
:data
If you use a wildcard character in a string with the = operator, the character is considered part of the
.string, not a wildcard
You can include calculations in expressions. Mathematical operators you can use include +-* and /. For
example, to find the counties with a population density of less than or equal to 25 people per square
:kilometer, you could use the query
Longer calculations evaluate * and / operators from left to right, then the + and - operators. For
:example, this query would multiply PRICE by AREA, then add TAX
To control the order calculations evaluate, use parentheses. Calculations within parentheses evaluate
:first. For example, to add TAX to PRICE, then multiply by AREA, use
To build an expression with more than one criteria when both criteria must be true, use the AND
operator. For example, to find areas of pine forest larger than 100 square kilometers, use this
:expression
When at least one of the criteria must be true, use the OR operator. For example, this expression will
:select any feature with at least one of the following conditions
:To exclude, use the NOT operator. For example, to select all the Pacific states except California, use