In relational algebra, a selection (sometimes called a restriction in reference to E.F. Codd's 1970 paper and ''not'', contrary to a popular belief, to avoid confusion with SQL's use of SELECT, since Codd's article predates the existence of SQL) is a

unary operation
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in ...

that denotes a subset
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented i ...

of a relation.
A selection is written as
$\backslash sigma\_(\; R\; )$ or $\backslash sigma\_(\; R\; )$ where:
* and are attribute names
* is a binary operation
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in ...

in the set $\backslash $
* is a value constant
* is a relation
The selection $\backslash sigma\_(\; R\; )$ denotes all tuple
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in m ...

s in for which holds between the and the attribute.
The selection $\backslash sigma\_(\; R\; )$ 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 $\backslash sigma\_(\; \backslash text\; )$ and the third table gives the result of $\backslash sigma\_(\; \backslash text\; )$.
More formally the semantics of the selection is defined as
follows:
: $\backslash sigma\_(\; R\; )\; =\; \backslash $
: $\backslash sigma\_(\; R\; )\; =\; \backslash $
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 aunary operation
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in ...

written as $\backslash sigma\_\backslash varphi(R)$ where $\backslash varphi$ is a propositional formula that consists of atom
Every atom is composed of a nucleus and one or more electrons bound to the nucleus. The nucleus is made of one or more protons and a number of neutrons. Only the most common variety of hydrogen has no neutrons.
Every solid, liquid, g ...

s as allowed in the normal selection and, in addition, the logical operators ∧ ( and), ∨ ( or) and $\backslash lnot$ ( negation). This selection selects all those tuple
In mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in m ...

s in for which $\backslash varphi$ holds.
For an example, consider the following tables where the first table gives the relation and the second the result of $\backslash sigma\_(\backslash text)$.
Formally the semantics of the generalized selection is defined as follows:
: $\backslash sigma\_\backslash varphi(R)\; =\; \backslash $
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:
: $\backslash sigma\_(R)\; =\; \backslash sigma\_\backslash varphi(R)\; \backslash cap\; \backslash sigma\_\backslash psi(R)$
: $\backslash sigma\_(R)\; =\; \backslash sigma\_\backslash varphi(R)\; \backslash cup\; \backslash sigma\_\backslash psi(R)$
: $\backslash sigma\_(R)\; =\; R\; -\; \backslash sigma\_\backslash varphi(R)$
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 (''true'', ''false'' and ''unknown'') 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.
References

External links

* http://cisnet.baruch.cuny.edu/holowczak/classes/3400/relationalalgebra/#selectionoperator {{DEFAULTSORT:Selection (Relational Algebra) Relational algebra