Selection (relational algebra)
In relational algebra, a selection is a unary operation written as σa θ b(R) or σa θ v(R) where:
- a and b are attribute names
- θ is a binary operation in the set {<, ≤, =, >, ≥}
- v is a value constant
- R is a relation
The selection σa θ b(R) selects all those tuples in R for which θ holds between the a and the b attribute.
The selection σa θ v(R) selects all those tuples in R for which θ holds between the a attribute and the value v.
For an example, consider the following tables where the first table gives the relation Person, the second table gives the result of σAge ≥ 34(Person) and the third table gives the result of σAge = Weight(Person).
Person | σAge ≥ 34(Person) | σAge = Weight(Person) | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
More formally the semantics of the selection is defined as follows:
- σa θ b(R) = {t | t ∈ R, t(a) θ t(b)}
- σa θ v(R) = {t | t ∈ R, t(a) θ v}
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.
In SQL, selections are performed by using WHERE
definitions in SELECT
, UPDATE
, and DELETE
statements.