Structured Query Language (SQL) is a programming language that is used to define one or more criteria that can consist of attributes, operators, and calculations. For example, you have a table of customer data, and you want to find those customers 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'".
When a query is specified for an update or search cursor, only the records satisfying that query are returned. An SQL query represents a subset of the single table queries that can be made against a table in an SQL database using the SQL SELECT statement. The syntax used to specify the WHERE clause is the same as that of the underlying database containing the data.
The following example filters the rows of a search cursor to only roads of a specific road class:
import arcpy
fc = "D:/St_Johns/data.gdb/roads"
# Create a search cursor using an SQL expression
with arcpy.da.SearchCursor(fc, ("roadclass", "name"), "roadclass = 2") as cursor:
for row in cursor:
# Print the name of the residential road
print(row[1])