Relational algebra operations

Operations in the Relational Data Model are defined by Relational Algebra. Relational Algebra is not based on the attributes, but rather on the order of values (components) in the tuple. There are five basic operations [7]:

- Union,
- Difference,
- Cartesian Product,
- Projection,
- Selection.

The Union of relations and is defined as:

The Difference of relations and , defined as:

The Cartesian Product of relations and is defined as:

The Projection is denoted as .
Assuming that there is a relation of arity , then:

For example is computed by taking each tuple from , and forming a 2-tuple set from fourth and second component of . Instead of using locations, attribute names can be used as well. Assuming that is the relation schema for the above relation. Then the above projection can also be denoted as . The resulting relation can be described by the following relation schema: .

The Selection is denoted as:

- Operands that are constants or component numbers; component is represented by ,
- The arithmetic comparison operators , , , , , ,
- The logical operators (and), (or), (not).

There are also some other algebraic operations defined as: Intersection, Quotient, Join, Natural Join or Semijoin. They are all derived from the basic ones.

The Intersection can be defined as:

The Quotient of relations and is denoted as .
Assuming that and are relations of arity and respectively, and , and
.
Then the quotient is a set of all ()-tuples
, such that for all -tuples
in , the tuple
is in :

The Join (also known as -Join) of and on columns and is defined as:

The Natural Join is a special case of the Join.
It is applicable only when both and have columns that are named by attributes.
Assuming that
are all the attribute names used for both and , then the Natural Join is defined as:

The Semijoin of relation by relation , written
, is the projection onto the attributes of of the natural join of and :

Relational Algebra becomes a natural way to formulate queries. Having selection and projection, a question about a single relation can be asked. Adding Cartesian product, the query can concern more than one relation. Applying union or difference, several queries can be combined, to form a more sophisticated one.

Igor Wojnicki 2005-11-07