 ## Operators

Operators manipulate individual data items (operands) and return a result. Mimer SQL uses the following operators:

### Set Operators

#### UNION or UNION ALL

Derives a final result set by combining two other result sets.

If you specify `UNION ALL`, the result consists of all rows in both results sets.

If you only specify `UNION`, the final result set is the set of all rows in both of the result sets, with duplicate rows removed.

#### EXCEPT or EXCEPT ALL

The except operator is used to combine two result sets to one where the combined result set is all records from the first result which is not present in the second result set. If except is specified without the `ALL` quantifier, duplicates are removed from the combined result set. If `ALL` is specified, duplicates are not removed.

#### INTERSECT or INTERSECT ALL

The intersect operator is used to combine two result sets to one where the combined result set is the records that are present in both result sets. If intersect is specified without the `ALL` quantifier, duplicates are removed from the combined result set. If `ALL` is specified, duplicates are not removed.

### Arithmetical Operators

Arithmetical operators are used in forming expressions, see Expressions.

The operators are:

• unary arithmetical (i.e. one argument operators)
• binary arithmetical (i.e. two argument operators)

#### Unary Arithmetical

 `+` leaves operand unchanged `-` changes sign of operand

#### Binary Arithmetical

 `+` addition `-` subtraction `*` multiplication `/` division `%` modulo

### String Operators

String operators are used in forming expressions, see Expressions.

#### String

 `||` concatenation

### Bit Operators

Bit operations:

 `&` bitwise AND operation `|` bitwise OR operation ^ bitwise XOR operation `~` bitwise complement `<<` left shift `>>` right shift

Bit operations are supported on integer data types, i.e. the operations are performed on the integer bit representation. When right shift is performed a so called arithmetic shift is performed. This means that the sign bit will be used to replace the bits as the shift to the right is made.

##### Result
`set ? = 9 | 3`
`11`
`set ? = cast(x'0f23' as int) &        cast(x'fff0' as int)`
`3872`
`set ? = cast(cast(x'0f23' as int) &         cast(x'fff0' as int) as binary(4))`
`X'00000F20'`
`select cast(~(1 << 7) as binary(8))from information_schema.ext_onerow`
`X'FFFFFFFFFFFFFF7F'`

### Comparison Operators

Comparison operators are used to compare operands in basic and quantified predicates. (Relational operators are used to compare operands in all other predicates, see Predicates.)

Both comparison and relational operators perform essentially similar functions. However, comparison operators are common to most programming languages, while the relational operators are more or less specific to SQL.

#### Comparison Operators

##### Explanation
=
equal to
<>
not equal to
<
less than
<=
less than or equal to
>
greater than
>=
greater than or equal to

`ALL`
`SOME`
`ANY`

### Logical Operators

##### Logical operator
`AND`
`OR`
`NOT`

The operators `AND` and `OR` are used to combine several predicates to form search conditions, see Search Conditions.

The operator `NOT` may be used to reverse the truth value of a predicate in forming search conditions. This operator is also available in predicate constructions to reverse the function of a relational operator, see Search Conditions.

### Operator Precedence

##### SQL
Postfix
`(`, `)`
Unary, complement
`+`, `-`, `~`
Multiplicative
`*`, `/`, `%`
`+`, `-`, `||`
Shift
`<<`, `>>`
Bitwise AND
`&`
Bitwise OR
`|`
Comparison operators
`=`, `<>`, `<`, `<=`, `>`, `>=`, `IS`, `IS DISTINCT FROM`
Negation
`NOT`
Boolean AND
`AND`
Boolean OR
`OR`
Assignment
`=`

Operators with the same precedence are evaluated from left to right.

##### Parenthesized execution order
`not false = true`
`not (false = true)`
`a | b & c | d = 110`
`(a | (b & c) | d) = 110`
`~10 + 5 * 8`
`(~10) + (5 * 8)`
1 / 2 * 10
(1 / 2) * 10
1 + 3 * 15 % 2 * 4
1 + ((3 * 15) % 2) * 4

Please note that the precedence of operators vary between different database vendors. Use parenthesis to make sure the operations are executed as intended.

### Standard Compliance

This section summarizes standard compliance concerning operators.

##### Compliance
Support for `%` modulo operator is a Mimer SQL extension. Mimer Information Technology AB Phone: +46 18 780 92 00 info@mimer.com