HOME

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, 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 o ...
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 of ...
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 o ...
written as \sigma_\varphi(R) where \varphi is a
propositional formula In propositional logic, a propositional formula is a type of syntactic formula which is well formed and has a truth value. If the values of all variables in a propositional formula are given, it determines a unique truth value. A propositional for ...
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, a ...
s as allowed in the normal selection and, in addition, the logical operators ∧ (
and or AND may refer to: Logic, grammar, and computing * Conjunction (grammar), connecting two words, phrases, or clauses * Logical conjunction in mathematical logic, notated as "∧", "⋅", "&", or simple juxtaposition * Bitwise AND, a boolea ...
), ∨ ( 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 false ...
). 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-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''). Computing In some progra ...
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 Where may refer to: * Where?, one of the Five Ws in journalism * where (command), a shell command * Where (SQL), a database language clause * Where.com, a provider of location-based applications via mobile phones * ''Where'' (magazine), a serie ...
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 Where may refer to: * Where?, one of the Five Ws in journalism * where (command), a shell command * Where (SQL), a database language clause * Where.com, a provider of location-based applications via mobile phones * ''Where'' (magazine), a serie ...
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