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 on ...
that denotes a
subset
In mathematics, 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 are ...
of a relation.
A selection is written as
or
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
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
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
and the third table gives the result of
.
More formally the semantics of the selection is defined as
follows:
:
:
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 on ...
written as
where
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 fo ...
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, and ...
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
(
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
holds.
For an example, consider the following tables where the first table gives the relation and the second the result of
.
Formally the semantics of the generalized selection is defined as follows:
:
The result of the selection is only defined if the
attribute
Attribute may refer to:
* Attribute (philosophy), an extrinsic property of an object
* Attribute (research), a characteristic of an object
* Grammatical modifier, in natural languages
* Attribute (computing), a specification that defines a prope ...
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:
:
:
:
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
Where, Inc. was a location-based media company in North America. Their main products were ...
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
Where, Inc. was a location-based media company in North America. Their main products were ...
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