Chapter 6
Chapter 6
Chapter 6
Example:
Thus in the above example we want to
extract employee information about
managers of the departments, the algebra
query using the JOIN operation will be.
EQUIJOIN Operation
The most common use of join involves join
conditions with equality comparisons only ( = ).
Such a join, where the only comparison
operator used is called an EQUIJOIN.
In the result of an EQUIJOIN we always have
one or more pairs of attributes (whose names
need not be identical) that have identical values
in every tuple since we used the equality logical
operator.
For example, the above JOIN expression is an
EQUIJOIN since the logical operator used is
the equal to operator ( =).
NATURAL JOIN Operation
The standard definition of natural join
requires that the two join attributes, or
each pair of corresponding join attributes,
have the same name in both relations.
If this is not the case, a renaming operation
on the attributes is applied first.
OUTER JOIN Operation
OUTER JOIN is another version of the
JOIN operation where non matching
tuples from the first Relation are also
included in the resulting
Relation where attributes of the second
Relation for a non matching tuples from
Relation one will have a value of NULL
Notation:
Cont…
When two relations are joined by a JOIN
operator, there could be some tuples in the
first relation not having a matching tuple
from the second relation, and the query is
interested to display these non matching
tuples from the first relation.
Such query is represented by the OUTER
JOIN.
SEMIJOIN Operation
A join where the result only contains
the columns from one of the joined
tables.
Useful in distributed databases, so we
don't have to send as much data over the
network.
Relational Calculus
A relational calculus expression creates a new
relation, which is specified in terms of
variables that range over rows of the stored
database relations (in tuple calculus) or over
columns of the stored relations (in domain
calculus).
In a calculus expression, there is no order of
operations to specify how to retrieve the
query result.
A calculus expression specifies only what
information the result should contain
rather than how to retrieve it.
Cont…
In Relational calculus, there is no description
of how to evaluate a query, this is the main
distinguishing feature between relational
algebra and relational calculus.
Relational calculus is considered to be a
nonprocedural language.
This differs from relational algebra, where we
must write a sequence of operations to specify
a retrieval request; hence relational algebra
can be considered as a procedural way of
stating a query.
Cont…
When applied to relational database, the calculus is
not that of derivative and differential but in a
form of first-order logic or predicate calculus, a
predicate is a truth-valued function with arguments.
When we substitute values for the arguments in the
predicate, the function yields an expression, called a
proposition, which can be either true or false.
If a predicate contains a variable, as in ‘x is a
member of staff ’, there must be a range for x.
When we substitute some values of this range for x,
the proposition may be true; for other values, it may
be false.
Cont…
If COND is a predicate, then the set off all
tuples evaluated to be true for the predicate
COND will be expressed as follows: