Guide To Writing Queries

And, Or, Not

8min

A query consists of one or multiple Query Terms, which are connected using the logical operators and or or.

Document image


Query Terms are grouped together in a right-associative manner. What that beauty of a sentence means is that if you write this:

name contains "inc" or name contains "ltd" and industry = "Banking"

It will be interpreted like this:

name contains "inc" or ( name contains "ltd" and industry = "Banking" )

This will match Accounts satisfying either of the following conditions:

  • name contains "inc"
  • name contains "ltd" and industry is "Banking"


In general, if you have something like this:



QT1 and QT2 or QT3 and QT4 or ...



It will be interpreted like this:



QT1 and ( QT2 or ( QT3 and ( QT4 or ( ... ) ) ) )



It doesn't matter if you use and or or.



Explicit parenthesis ( ) can be used to change this however you wish.

( name contains "inc" or name contains "ltd" ) and industry = "Banking"

This will match Accounts satisfying both of the following conditions:

  • name contains "inc" or "ltd"
  • industry is "Banking"

You can also wrap one or more Query Terms in not ( ), which negates the terms:

not ( name contains "inc" or name contains "ltd" ) and industry = "Banking"

This will match Accounts satisfying both of the following conditions:

  • name contains neither "inc" nor "ltd"
  • industry is "Banking"
name contains "inc" or not ( name contains "ltd" and industry = "Banking" )

This will match Accounts satisfying either of the following conditions:

  • name contains "inc"
  • either name doesn't contain "ltd" or industry isn't "Banking", or both


There are some nuances about how negations and searching fields on linked records interact with each other, which might not be immediately apparent. Check out the section on linked fields.