Combining predicates with AND and OR logic

Often you need more than one predicate in your query to select the items that you want in your result. For example, to select someone named “John Smith” generally requires you to specify two predicate expressions:

last_name = "Smith"
first_name = "John

To select the record that you need, both expressions must be true. You need a person’s last name to be “Smith” and that same person’s first name to be “John.” You do not want only one of the expressions to be true. You do not want to select people whose last name is “Smith” or first name is “John.”

For other requirements, you need to combine predicate expressions, any of which may be true, to select the items that you want. For example, to select addresses from Chicago or Los Angeles also generally requires two predicates:

city = "Chicago"
city = "Los Angeles"

To select the addresses that you need, either expression may be true. You want an address to have either “Chicago” or “Los Angeles” as the city.