# Precedence Among Operators

Go Up to Determining Precedence of Operators

## Among Operators of Different Types

The following table lists the evaluation order of different InterBase operator types, from first evaluated (highest precedence) to last evaluated (lowest precedence):

Operator precedence by operator type
Operator type Precedence Explanation

String

Highest

Strings are always concatenated before all other operations take place.

Mathematical

Math is performed after string concatenation, but before comparison and logical operations.

Comparison

Comparison operations are evaluated after string concatenation and math, but before logical operations.

Logical

Lowest

Logical operations are evaluated after all other operations.

## Among Operators of the Same Type

When an expression contains several operators of the same type, those operators are evaluated from left to right unless there is a conflict where two operators of the same type affect the same values.

For example, in the mathematical equation, 3 + 2 * 6, both the addition and multiplication operators work with the same value, 2. Evaluated from left to right, the equation evaluates to 30: 3+ 2 = 5; 5 * 6 = 30. InterBase follows standard mathematical rules for evaluating mathematical expressions, that stipulate multiplication is performed before addition: 2 *6 = 12; 3 + 12 = 15.

The following table lists the evaluation order for all mathematical operators, from highest to lowest:

Mathematical operator precedence
Operator Precedence Explanation

*

Highest

Multiplication is performed before all other ­mathematical operations.

/

Division is performed before addition and subtraction.

+

Lowest

Subtraction is performed after all other mathematical operations.

InterBase also follows rules for determining the order in which comparison operators are evaluated when conflicts arise during normal left to right evaluation. The next table describes the evaluation order for comparison operators, from highest to lowest:

Comparison operator precedence
Operator Precedence Explanation

=,==

Highest

Equality operations are evaluated before all other comparison operations.

<>, !=, ~=, ^=

>

<

>=

<=

>, ~>, ^>

<, ~<, ^<

Lowest

Not less than operations are evaluated after all other comparison operations.

`ALL`, `ANY`, `BETWEEN`, `CONTAINING`, `EXISTS`, `IN`, `LIKE`, `NULL`, `SINGULAR`, `SOME`, and `STARTING WITH` are evaluated after all listed comparison operators when they conflict with other comparison operators during normal left to right evaluation. When they conflict with one another they are evaluated strictly from left to right.

When logical operators conflict during normal left to right processing, they, too, are evaluated according to a hierarchy, detailed in the following table:

Logical operator precedence
Operator Precedence Explanation

NOT

Highest

NOT operations are evaluated before all other logical operations.

AND

AND operations are evaluated after NOT operations, and before OR operations.

OR

Lowest

OR operations are evaluated after all other logical operations.