Selection (relational algebra)

From Wikipedia, the free encyclopedia
Jump to: navigation, search

In relational algebra, a selection (sometimes called a restriction to avoid confusion with SQL's use of SELECT) is a unary operation written as \sigma_{a \theta b}( R ) or \sigma_{a \theta v}( R ) where:

  • a and b are attribute names
  • \theta is a binary operation in the set \{\;<, \le, =, \ne, \ge, \;>\}
  • v is a value constant
  • R is a relation

The selection \sigma_{a \theta b}( R ) selects all those tuples in R for which \theta holds between the a and the b attribute.

The selection \sigma_{a \theta v}( R ) selects all those tuples in R for which \theta 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 \sigma_{Age \ge 34}( Person ) and the third table gives the result of \sigma_{Age = Weight}( Person ).

Person \sigma_{Age \ge 34}( Person ) \sigma_{Age = Weight}( Person )
Name Age Weight
Harry 34 80
Sally 28 64
George 29 70
Helena 54 54
Peter 34 80
Name Age Weight
Harry 34 80
Helena 54 54
Peter 34 80
Name Age Weight
Helena 54 54

More formally the semantics of the selection is defined as follows:

\sigma_{a \theta b}( R ) = \{\ t : t \in R,\ t(a) \ \theta \ t(b) \ \}
\sigma_{a \theta v}( R ) = \{\ t : t \in R,\ t(a) \ \theta \ v \ \}

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.

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 (true, false and unknown) instead of the usual two.

See also[edit]

References[edit]