Some datasets, like this Code Enforcement - Building and Property Violations dataset from the City of Boston, represent data that can be either at a specific address or within a block of addresses. This dataset has three fields that are used for the address:
stno
, for either the exact street address or the start of the rangesthigh
, for the upper end of a “block range” when setstreet
, for the street nameTo query this dataset, we want to:
stno
stno
and sthigh
if there is a rangeWith SoQL, this is fairly straightforward. By using the boolean AND
and OR
operators, we can set up a $where
query like street = '$street_name' AND (stno = '$street_name' OR (stno <= '$street_name' AND sthigh >= '$street_name'))
(where $street_name
and $street_name
represent our input street name and number).
For example, here’s the query for “228 Market”: