Selection (relational algebra)


In relational algebra, a selection is a unary operation that denotes a subset of a relation.
A selection is written as
or where:
The selection denotes all tuples in for which holds between the and the attribute.
The selection denotes all tuples in for which holds between the attribute and the value.
For an example, consider the following tables where the first table gives the relation, the second table gives the result of and the third table gives the result of .
More formally the semantics of the selection is defined as
follows:
The result of the selection is only defined if the attribute names that it mentions are in the heading of the relation that it operates upon.

Generalized selection

A generalized selection is a unary operation written as where is a propositional formula that consists of atoms as allowed in the normal selection and, in addition, the logical operators ∧, ∨ and . This selection selects all those tuples in for which holds.
For an example, consider the following tables where the first table gives the relation and the second the result of.
Formally the semantics of the generalized selection is defined as follows:
The result of the selection is only defined if the attribute names that it mentions are in the header of the relation that it operates upon.
The generalized selection is expressible with other basic algebraic operations. A simulation of generalized selection using the fundamental operators is defined by the following rules:

Computer languages

In computer languages it is expected that any truth-valued expression be permitted as the selection condition rather than restricting it to be a simple comparison.
In SQL, selections are performed by using WHERE definitions in SELECT, UPDATE, and DELETE statements, but note that the selection condition can result in any of three truth values instead of the usual two.
In SQL, general selections are performed by using WHERE definitions with AND, OR, or NOT operands in SELECT, UPDATE, and DELETE statements.