What would you like to know more about?

SQL Comparisons

SQL supports many types of comparisons. Comparisons start with the basic pattern:

<field> <operator> <value>

Different Operators For Different Types of Values

Valid operators change depending on the value you are comparing:

  • The operator for NULL is different than the operators for numbers or text.
  • The operators for a list or range is different than the operator for a single value.
  • The operator for exact text is different than text with a wildcard.

Some comparisons require an extended syntax, with examples below. These include IN, BETWEEN, and NULL.

Text Comparisons & Operators

Here are comparisons used in the Advanced Search Tool and their corresponding operators and values in SQL:

Table 1. SQL Text Comparison Operators
ComparisonDescriptionExample TermExample ResultOperator/Value
Exact MatchReturns ony the exact search termJohnJohn (but not Johnny or Jonathan)= 'John'
Begins WithLooks at the beginning of the text fieldJoJohn, Johnny, Jonathan, JoannaLIKE 'Jo%'
Ends WithLooks at the end of the text fieldcom.com email addresses but not comcast@sbcglobal.netLike '%com'
ContainsLooks anywhere in the field to find a matchGroupSmall Group, Group Life, Red Group, GroupLIKE '%Group%'
INLooks in a supplied list for exact matchesMember, AttendeeMember, AttendeeIN ('Member", Attendee')
BETWEENLooks in a range between two values (inclusive)J to KJansen, Johnson, Jylon (but not Kane, because it's after K alphabetically)BETWEEN 'J' and 'K'
NULLLooks for empty fieldsWill return records where the field is empty.IS NULL
NOT NULLLook for fields with valuesIS NOT NULL
Not EqualLooks for anything but exact matchJohnJonnny, Jonathan, Jerry<> 'John'

Number Comparisons

Table 2. Number Comparison Operators
ComparisonDescriptionExample TermExample ResultOperator/Value
=Equals44= 4
>Greater Than45, 6, 7, (and up)> 4
<Less Than 40,1,2,3 (and negative values if the field supports them)< 4
> = Greater Than or Equal To44,5,6, (and up)> = 4
< = Less Than or Equal To40,1,2,3,4 (and negative values if the field supports them)< = 4
< >Not Equal To40,1,2,3,5<> 4
INLooks in a supplied list for exact matches. Supports the NOT keyword as in "NOT IN."1,3,51,3,5IN (1,3,5)
BETWEENLooks in a range between two values (inclusive). Supports the NOT keyword as in "NOT BETWEEN"4 to 64,5,6BETWEEN 4 and 6
NULLLooks for empty fields. Supports the NOT keyword as in "IS NOT NULL"Will return records where the field is empty.IS NULL

The Advanced Search Tool provides options to create many types of filters. Each filter is a comparison that further limits the number of resulting records.