# Union¶

## Union operator `+`

¶

The union operator is not yet implemented -- this page serves as the specification for the upcoming implementation. Union is rarely needed in practice.

The result of the union operator `A + B`

contains all the tuples from both operands.

### Principles of union¶

- As in all operators, the order of the attributes in the operands is not significant.
- Operands
`A`

and`B`

must have the same primary key attributes. Otherwise, an error will be raised. - Operands
`A`

and`B`

may not have any common non-key attributes. Otherwise, an error will be raised. - The result
`A + B`

will have the same primary key as`A`

and`B`

. - The result
`A + B`

will have all the non-key attributes from both`A`

and`B`

. - For tuples that are found in both
`a`

and`b`

(based on the primary key), the non-key attributes will be filled from the corresponding tuples in`A`

and`B`

. - For tuples that are only found in either
`A`

or`B`

, the other operands' non-key attributes will filled with NULLs.

### Examples of union¶

Example 1 : Note that the order of the attributes does not matter.

Example 2 : Non-key attributes are combined from both relations and filled with NULLs when missing.

### Properties of union¶

- Commutative:
`A + B`

is equivalent to`B + A`

. - Associative:
`(A + B) + C`

is equivalent to`A + (B + C)`

.