HOME

TheInfoList



OR:

In
relational algebra In database theory, relational algebra is a theory that uses algebraic structures for modeling data and defining queries on it with well founded semantics (computer science), semantics. The theory was introduced by Edgar F. Codd. The main applica ...
, 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 that denotes a
subset In mathematics, a Set (mathematics), set ''A'' is a subset of a set ''B'' if all Element (mathematics), 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 a ...
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, a binary operation ...
in the set \ * is a value constant * is a relation The selection \sigma_( R ) denotes all
tuple In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is o ...
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 written as \sigma_\varphi(R) where \varphi is a propositional formula that consists of
atom Atoms are the basic particles of the chemical elements. An atom consists of a atomic nucleus, nucleus of protons and generally neutrons, surrounded by an electromagnetically bound swarm of electrons. The chemical elements are distinguished fr ...
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 not or logical complement, is an operation (mathematics), operation that takes a Proposition (mathematics), proposition P to another proposition "not P", written \neg P, \mathord P, P^\prime or \over ...
). This selection selects all those
tuple In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is o ...
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-value In logic and mathematics, a truth value, sometimes called a logical value, is a value indicating the relation of a proposition to truth, which in classical logic has only two possible values ('' true'' or '' false''). Truth values are used in c ...
d 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