The Power of SQL & Query Builder

I know this post covers something probably very obvious to many technical users of ArcGIS.   However some of us ArcGIS users are not necessarily aware of Query Builder and it’s uses.  So this advice is for people like us/them.

You may have noticed the “Definition Query” tab in your “Layer Properties” dialog box (right click on your layer and select ‘properties’). As ESRI says in the ArcGIS helpfile:

Query expressions are used in ArcGIS to select a subset of features and table records.

Clear as mud to those not familiar with standard SQL expressions!   Anyway why would you use? Or more importantly why would I use it?

Here was my problem, for a particular project I have imported into a Geodatabase an AutoCAD file that has many layers and a lot of features.  So I am displaying each former AutoCAD layer with different symbology but using the same feature class in the geodatabase each time (clear enough?).

How did I select you? You’re not there!

Using the Symbology tab in the Layer properties I can display only those features that I am interested in.   Now I can make some nice paper maps and the like!   The trouble is when I want to now edit that layer I keep on selecting for some reason the features that I haven’t assigned symbology to.   Very annoying and very frustrating.

So what the Query Builder allows me to do is select only the features that are in this case by layer name field (it’s from AutoCAD) to be used.   Now when I go to edit this layer only those features I have given symbology to are selectable.    Okay I apologise if this doesn’t make sense to you but then perhaps you haven’t had the same issue I have.

Anyway say you have three features types (formerly layers in AutoCAD) that you want display these are:

  • Primary Road
  • Secondary Road
  • Track
All you need to do is type (or construct) the following code into the Query Builder:

“Layer” IN(‘Primary Road’ , ‘Secondary Road’, ‘Local’ )

I’m not here to explain how it works as to be honest I’m not sure and its probable that you can do this another way.   However this works for me, if you have any suggestions as to a better code, I’m all ears so please add a comment after this post and I’ll amend the advice!

I looked for help on the ArcGIS forums beforing writing this post and used the following discussion thread:
Mulitple NOT expressions in query builder? 

Suggested Reads (I guess): Getting to Know ArcGIS Desktop: The Basics of ArcView, ArcEditor, and ArcInfo Updated for ArcGIS 9 (Getting to Know series) and SQL For Dummies

1 Comment

Comments are closed.