Select Operator
Select Operator
The cartesian product is a binary operator as it works on two relations. The cartesian product
combines the tuples from both the relations given in its argument. The symbol of the cartesian
product is X.
Consider, that we have two relations instructor and department relation.
If we apply the cartesian product on the instructor X department relation the result would be:
Cartesian product
o The Cartesian product is used to combine each row in one table with each row in the other
table. It is also known as a cross product.
o It is denoted by X.
1. Notation: E X D
o The relations to which Cartesian product operation is applied need not necessary to be union
compatible.
o The total number of rows in the result operation is equal to the product of the number of rows
in the first and second relations, i.e.
Total number of tuples of data = Total number of tuples of E + Total number of tuples of D
o The resulting relation may have duplicate properties if some properties of the two relations are
defined on common domains.
o The resulting degree of action is equal to the sum of the degrees of all relations
Derived Operators
Set Intersection Operator
Set interaction operator is an additional relational algebra operator. The set operator is a binary
operator and it works on two provided relations. The set operator returns the tuples that are
present in both the specified relations. The symbol of set intersection operators is Ո.
If we apply set intersection on relation instructor_1 and instructor_2 i.e. instructor_1 Ո
instructor_2 then the result would be:
Intersection:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples that are
in both R & S.
o It is denoted by intersection ∩.
1. Notation: R ∩ S
Joins
The natural join integrates two relations from the database based on the common attributes of
both the relations. There are several kinds of joins equijoin, theta joins, semi-join and left outer
join, right outer join and full outer join.
I have explained the concept of all these joins in my previous content join operations in SQL.
Please click on this URL https://binaryterms.com/join-operations-in-sql.html to get a better
understanding of joins and their types.
Division Operator
The division operator is a binary operator that works on two relations. The division operator
returns the tuples of the first relation based on the information present in the second table.
Consider we have two relations instructor relation and department relation.
Now if we require the name of the instructors who teach in all the departments. Then we will
apply division operation on the two relations i.e. instructor ÷ department.
Relational algebra is based on the set theory which is a mathematical concept due to
which it has a scope of development.
Like mathematics there can be many expressions for the same operation, in a similar way
if there are two relational algebraic expressions for the same operation then the query
optimizer will switch to the most efficient query.
It is a high-level query language.
Limitations
Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ). If no rename
operation is applied then the names of the attributes in a resulting relation are the same as those in the
original relation and in the same order.
Example: We can use the rename operator to rename STUDENT relation to STUDENT1.
1. ρ(STUDENT1, STUDENT)
Note: Apart from these common operations Relational algebra can be used in Join operations.
8. Join Operation:
A join operation combines two or more relations to form a new relation such that new relation contains
only those tuples from different relations that satisfy the specified criteria. It forms a new relation which
contains all the attributes from both the joined relations whose tuples are those defined by the
restrictions applies i.e. the join condition applied on two participating relations. The join is performed on
two relations, who have one or more attributes in common. These attributes must be domain
compatible i.e. they have same data type. It is a binary operation. The Join operation is denoted by a Join
symbol. The general from of representing a join operation on two relations P and Q is
1. P⋈ <join_condion> Q
When we use equality operator in the join condition then such a join is called EQUI Join. It is mostly
commonly used Join.
o Like the cartersion product, join operations are commutative. Using this property, we can choose
which relation can be the inner and which one the outer while joining two relations. If P and Q
are two relations then,
P⋈ Q = Q ⋈ P
o Rows whose join attribute is null do not appear in the resulting relation.
o We can also join more than two relations by increasing the complexity.
o Joins are generally used when a relationship exists between relations such as where the join
condition is based on the primary key and foreign key columns.
o Join is a very powerful operator and together with projection form a base for normalization i.e.
theoretical support for designing database relations.
o If the attributes on which the join is performed have the same name in both the relations then
renaming is necessary for the EQUIJOIN operation and unnecessary for the NATURAL JOIN
operation because the former i.e. EQUI JOIN both exist as a result of the common attribute
relation but the latter In i.e., natural additive consequent relations have only one common
property.
o Division Operation:
o The division operation results in a new relation such that every tuple appearing in the resulting
relation must exist in the dividend relation. In the combination of each tuple in the denominator
relation. It is a binary operation that operates on two relations. The division is represented by a
symbol "÷".
o The division operation is suited to queries that include the phrase "for all".