Projection (relational algebra)
Operation that restricts a relation to a specified set of attributes
In relational algebra, a projection is a unary operation written as , where
is a relation and
are attribute names. Its result is defined as the set obtained when the components of the tuples in
are restricted to the set
, it discards (or excludes) the other attributes.
In practical terms, if a relation is thought of as a table, then projection can be thought of as picking a subset of its columns. For example, if the attributes are (name, age), then projection of the relation {(Alice, 5), (Bob, 8)} onto attribute list (age) yields {5,8}, we have discarded the names, and only know what ages are present.
Projections may also modify attribute values. For example, if has attributes
,
,
, where the values of
are numbers, then
is like
, but with all
-values halved.
02Example
For an example, consider the relations depicted in the following two tables which are the relation Person and its projection on (some say "over") the attributes Age and Weight:
|
|
Suppose the predicate of Person is "Name is age years old and weighs weight." Then the given projection represents the predicate, "There exists Name such that Name is age years old and weighs weight."
Note that Harry and Peter have the same age and weight, but since the result is a relation, and therefore a set, this combination only appears once in the result.
03Formal definition
More formally the semantics of projection are defined as follows:
where is the restriction of the tuple
to the set
so that
where is an attribute value,
is an attribute name, and
is an element of that attribute's domain, see Relation (database).
The result of a projection is defined only if
is a subset of the header of
.
Projection over no attributes at all is possible, yielding a relation of degree zero. In this case the cardinality of the result is zero if the operand is empty, otherwise one. The two relations of degree zero are the only ones that cannot be depicted as tables.
Sources and credits
This article is adapted from the Wikipedia article “Projection (relational algebra)”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.