Use comparison operators to perform comparisons on data in SELECT queries. The following outlines the comparison operators supported by the SQL engine.
Operator |
Description |
|---|---|
< |
Less than |
> |
Greater than |
= |
Equal to |
<> |
Not equal to |
>= |
Greater than or equal to |
<= |
Less than or equal to |
Use comparison operators to compare two like values. Values compared can be field values, literals, or calculations. The result of the comparison is a boolean value that is used in contexts such as WHERE clauses to determine on a line-by-line basis if a line meets the filtering criteria. The following example uses the >= comparison operator to show only the Invoices where the GrossAmount field is greater than or equal to 10000:
SELECT * FROM INHEAD WHERE GrossAmount >= 10000
Comparisons must be between two values of the same or a compatible data type. The result of a comparison operation can be modified by a logical operator, such as NOT. The following example uses the >= comparison operator and the logical NOT operator to show only Invoices where the GrossAmount field is not greater than or equal to 10000:
SELECT * FROM INHEAD WHERE NOT (GrossAmount >= 10000)
NULL values can only be compared for equality or non-equality and any other comparison will evaluate to a Boolean False value.
Comparison operators can only be used in a WHERE or HAVING clause, or in the ON clause of a join. They cannot be used in the SELECT clause. The only exception to this would be within the first argument to the IF() function, that allows comparison expressions for performing IF...ELSE boolean logic.