About Boolean AND and OR

Using AND to combine predicates that all must be true

In SQL, you combine predicates with the AND keyword if all must be true to include an item in the result.

WHERE last_name = "Smith" AND first_name = "John"

With the query builder APIs, you combine predicates by calling predicate methods on the query object one after the other if all must be true.

query.compare(Contact#LastName, Equals, "Smith")
query.compare(Contact#FirstName, Equals, "John")

You can also use the and method to make the AND combination of the predicates explicit. For example, the following code is equivalent to the previous example:

query.and( \ andCriteria -> {
  andCriteria.compare(Contact#LastName, Equals, "Smith")
  andCriteria.compare(Contact#FirstName, Equals, "John")
})

See also

Using OR to combine predicates that require at least one to be true

In SQL, you combine predicates with the OR keyword if one or more must be true to include an item in the result.

WHERE city = "Chicago" OR city = "Los Angeles"

With the query builder APIs, you combine predicates by calling the or method on the query object if one or more must be true.

query.or( \ orCriteria -> {
  orCriteria.compare(Address#City, Equals, "Chicago")
  orCriteria.compare(Address#City, Equals, "Los Angeles")
})