selection (relational algebra)

TheInfoList

OR:

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 $\sigma_\left( R \right)$ or $\sigma_\left( R \right)$ 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 $\$ * is a value constant * is a relation The selection $\sigma_\left( R \right)$ 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 $\sigma_\left( R \right)$ 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 $\sigma_\left( \text \right)$ and the third table gives the result of $\sigma_\left( \text \right)$. More formally the semantics of the selection is defined as follows: : $\sigma_\left( R \right) = \$ : $\sigma_\left( R \right) = \$ 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 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 $\sigma_\varphi\left(R\right)$ where $\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 $\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 $\varphi$ holds. For an example, consider the following tables where the first table gives the relation and the second the result of $\sigma_\left(\text\right)$. Formally the semantics of the generalized selection is defined as follows: : $\sigma_\varphi\left(R\right) = \$ 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: : $\sigma_\left(R\right) = \sigma_\varphi\left(R\right) \cap \sigma_\psi\left(R\right)$ : $\sigma_\left(R\right) = \sigma_\varphi\left(R\right) \cup \sigma_\psi\left(R\right)$ : $\sigma_\left(R\right) = R - \sigma_\varphi\left(R\right)$

# 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.