When you add a dataset as a layer to a map or scene, you often only want to work with and draw a subset of the features. For example, you may want to display only the cities that exceed a certain population threshold, or only the streams that are not intermittent. You construct definition queries to filter exactly the features you want available in the map.
Definition queries are comprised of one or more clauses. They are written in SQL syntax, constructed using the query builder. See Write a query in the query builder to learn how to work with clauses and queries, and save and load queries from files.
Create definition queries for a layer or table
To create a definition query on a layer, follow these steps:
- Ensure the layer or table is selected in the Contents pane.
- Under Feature Layer, on the Data tab, in the Definition Query group, click Build Definition Query to open the Layer Properties dialog box with its Definition Query tab open.
- Click New definition query.
A new query is created, with a default name and a single, unfinished clause.
- Choose values from the menus to construct the clause. These menus and their values are specific to the underlying source data.
- Click Update to verify and add the clause to the query.
- Optionally, click Add Clause to add another clause to the query.
- Optionally, hover over the query name and click to rename it.
- To verify and finalize the query, click Apply.
- To add another definition query to the same layer or table, click New definition query.
Modify an existing query
To modify a query, hover over a query and follow any of these actions:
- To modify, add, or remove clauses from the query, click Edit .
- To edit a clause, hover over the clause and click Edit Clause to open the clause component menus. Adjust values as necessary.
- To remove a clause from the query, click Remove Clause .
- To add a clause to the query, click Add Clause .
- To remove the query from the layer or table, click Remove Query .
- To export the query syntax to a query expression file, click Save .
- To replace the current query with a different query from a query expression file (.exp file extension), click Load .
Work with multiple definition queries
You can define more than one definition query for a layer or table, and switch between them. Only one is active at any time, or you can have no queries active. The definition queries are stored as a property of the layer or table.
To switch between definition queries, follow these steps:
- Ensure that the layer is selected in the Contents pane.
- Under Feature Layer or Standalone Table, on the Data tab, in the Definition Query group, choose a query from the Definition Query menu to apply to the layer.
- Alternatively, you can set the active query from the Layer Properties or Standalone Table Properties dialog box.
- Click Set as Active to apply that query to the layer or table. Any other queries become inactive. The active query is named at the bottom of the Properties dialog box. If you have many queries listed and the active query is out of view, click Show the active definition query to scroll to it.
- Click Clear active query to have no query applied to the layer or table. All queries are retained by the layer or table, but none of them are currently applied.
Set definition queries on multiple layers or tables at once
If multiple layers or tables share definition queries with a common name—even if the content of the queries are not the same—the queries can be activated for the layers simultaneously. This means you can construct a number of related queries for a certain scenario, and apply them all at once. You can then switch to a different set of queries to satisfy a different scenario.
To apply definition queries with a common name to multiple layers or tables simultaneously, follow these steps:
- Ensure the layers or tables are selected in the Contents pane.
- Under Feature Layer or Standalone Table, on the Data tab, in the Definition Query group, choose a query from the Definition Query menu to apply to the layer. Only definition queries with a name common to all selected layers are shown.
Sharing layers with definition queries
When a layer is shared as a feature service or within a map service, only the active definition query is retained and honored. All other inactive definition queries are dropped.