Relation Algebra Operation
Relation Algebra Operation
Relation Algebra Operation
A MINUS B={1,4,5}
B MINUS A is empty or null because there is not any value, which is in
B but not in A.
Cartesian Product
In mathematics, the Cartesian product of two sets is the set of all
ordered pairs of elements such that the first element in each pair belongs
to the first set and the second element in each pair belongs to the second
set. It is denoted by cross (×). It is for example, given two sets:
S1 = {1,2,3}
and
S2={4,5,6}
The Cartesian product S1 × S2 is the set:
{(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)}
Special Relational Operators:
(i) Selection
(ii) Projection
(iii) Join
(iv) Division
Selection
The selection operator yields a horizontal subset of a given relation that
is, that subset of tuples or rows of table should be selected within the
given relation for which a particular condition is satisfied.
In mathematics, a set can have any number of subsets. A set is said to be
a subset of another if all its members are also members of the other set.
Thus, in the following example:
S1 ={1,2,3,4,5} S2 = {2,3,4}
S2 is a subset of S1. Since the body part of a table is a set, it is possible
for it to have subsets, that is, a selection from its tuples can be used to
form another relation. However, this would be a meaningless operation if
no new information were to be gained from the new relation. On the
other hand, a subset of, say an EMPLOYEE relation, which contained all
tuples where the employee represent those employees who earn more
than some given values of salary, would be useful. What is required is
that some explicit restriction be placed on the sub-setting operation.
Restriction as originally defined was defined on relations only and is
achieved using the comparison operators such as equal to (=), not equal
to (< >), greater than (>), less than (<), greater than or equal to (>=) and
less than or equal to (<=).
Examples:
S WHERE CITY = ‘Qadian’
P WHERE WEIGHT < 15
SP where Sno = ‘S1’ and Pno=’P1’
Projection
The most general form of join operation is called a theta join, where
theta has the same meaning as ‘compares with’ as it was used in the
context of the restriction operation. That is, it stands for any of the
comparative operators equals, not equals, greater than and so forth. A
theta join is performed on two tables, which have one or more columns
in common which are domain compatible.
It forms a new table which contains all the columns from both the joined
tables whose tuples are those defined by the restriction applied.
The examples given so far have all been of so-called inner joins. The fact
that Jones makes Rubbers is not recorder in any of the resultant tables
from the joins, because the joining values must exit in both tables. If it
suffices that the value exist in only one table, then a so-called outer join
is produced.
The expression A JOIN B is defined if and only if, for every unqualified
attribute-name that is common to A and B, the underlying domain is the
same for both relations. Assume that this condition is satisfied. Let the
qualified attribute-names for A and B, in their left-to-right order, be
A.A1,……A.Am AND B.B(m+1)……….., B.B(m+n), respectively;
let Ci…, Cj be the unqualified attribute name that are common to A and
B and let Br,……….Bs be the unqualified attribute-names remaining for
B (with their relative order undisturbed ) after removal of Ci,…….Cj.
where A.Ci=B.Ci
and ……………
and A.Cj=B.Cj……….
Apply this definition to JOIN operation on Emp and Dept tables with
following attributes:
EMP (empno, ename, job, sal, deptno)
DEPT ( deptno, dname, loc)
EMP JOIN DEPT = EMP TIMES DEPT
[emp.empno, emp.ename, emp.job,emp.sal, emp.deptno, dept.dname,
dept.loc]
where EMP.deptno = DEPT.deptno
So, we can say that JOIN is a combination of Product, Selection and
Projection operators. JOIN is an associative operator, which means:
(A JOIN B) JOIN C = A JOIN (B JOIN C).
JOIN is also commutative.
A JOIN B = B JOIN A
Division