HOME

TheInfoList



OR:

In
relational algebra In database theory, relational algebra is a theory that uses algebraic structures with a well-founded semantics for modeling data, and defining queries on it. The theory was introduced by Edgar F. Codd. The main application of 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, an unary operation is an operation with only one operand, i.e. a single input. This is in contrast to binary operations, which use two operands. An example is any function , where is a set. The function is a unary operation ...
that denotes a
subset In mathematics, set ''A'' is a subset of a set ''B'' if all elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are unequal, then ''A'' is a proper subset o ...
of a relation. A selection is written as \sigma_( R ) or \sigma_( R ) where: * and are attribute names * is a
binary operation In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two. More specifically, an internal binary op ...
in the set \ * is a value constant * is a relation The selection \sigma_( R ) denotes all
tuple In mathematics, a tuple is a finite ordered list (sequence) of elements. An -tuple is a sequence (or ordered list) of elements, where is a non-negative integer. There is only one 0-tuple, referred to as ''the empty tuple''. An -tuple is defi ...
s in for which holds between the and the attribute. The selection \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 \sigma_( \text ) and the third table gives the result of \sigma_( \text ). More formally the semantics of the selection is defined as follows: : \sigma_( R ) = \ : \sigma_( R ) = \ 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, an unary operation is an operation with only one operand, i.e. a single input. This is in contrast to binary operations, which use two operands. An example is any function , where is a set. The function is a unary operation ...
written as \sigma_\varphi(R) 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, gas ...
s as allowed in the normal selection and, in addition, the logical operators ∧ ( and), ∨ ( or) and \lnot (
negation In logic, negation, also called the logical complement, is an operation that takes a proposition P to another proposition "not P", written \neg P, \mathord P or \overline. It is interpreted intuitively as being true when P is false, and fals ...
). This selection selects all those
tuple In mathematics, a tuple is a finite ordered list (sequence) of elements. An -tuple is a sequence (or ordered list) of elements, where is a non-negative integer. There is only one 0-tuple, referred to as ''the empty tuple''. An -tuple is defi ...
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_(\text). Formally the semantics of the generalized selection is defined as follows: : \sigma_\varphi(R) = \ 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_(R) = \sigma_\varphi(R) \cap \sigma_\psi(R) : \sigma_(R) = \sigma_\varphi(R) \cup \sigma_\psi(R) : \sigma_(R) = R - \sigma_\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