0% found this document useful (0 votes)
30 views39 pages

Relation Algebra

The document discusses relation algebra and its fundamental operations. Relation algebra is a procedural query language that performs algebraic operations on relations. Its operations are classified as unary, which take one relation as input, or binary, which take two or more relations as input. The fundamental operations discussed are select, project, union, set difference, cartesian product, and rename. Additional operations like set intersection, inner join, division, and outer join are also covered. Examples are provided to illustrate how each operation works on relations.

Uploaded by

spacely.iq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views39 pages

Relation Algebra

The document discusses relation algebra and its fundamental operations. Relation algebra is a procedural query language that performs algebraic operations on relations. Its operations are classified as unary, which take one relation as input, or binary, which take two or more relations as input. The fundamental operations discussed are select, project, union, set difference, cartesian product, and rename. Additional operations like set intersection, inner join, division, and outer join are also covered. Examples are provided to illustrate how each operation works on relations.

Uploaded by

spacely.iq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Group members

• Eddy Kimani SCT212-0596/2021


• Kinyua Kevin SCT 212-0658/2021
• Victor Mwai SCT 212-0202/2021
• Tania Maina SCT 212-0179/2021
• Katuu Bryson SCT212-0205/2021
Relation Algebra
• It is a procedural query language
• It is a set of operations on relation(s)
• It is a set of algebraic operations
• Classified into two;
a. Unary(Takes one relation as an input)
b. Binary(Takes more than one relations as an input)
Fundamental operations
• Select (σ)
• Project(∏)
• Union(U)
• Set difference(-)
• Cartesian Product(X)
• Rename(ρ)
Additional Operations
• Set intersection
• Inner join(theta join, equijoin, naturaljoin)
• Division operation
• Outer join(left, right, full)
Select operation(σ)
• Selects the tuple that satisfy a given predicate/condition.
• It is denoted by the lowercase Greek letter sigma(σ).
• Syntax:
 Comparison operators: =,<,>, ≤,≥,and ≠
 Connectives AND(V),OR(Λ),NOT(⌐)
• It is a unary operator
Select operation(σ)
Example
Project Operation(∏)
Returns its argument relation with certain attributes left out.
It’s a unary operator
It is denoted by the uppercase greek letter pi(∏)
In the case we have duplicate values, the duplicate rows are eliminated
Project Operation(∏)
Example
Project Operation(∏)
Example
Set difference(-)
It is like the set difference in SET theory
It is a binary operation
Used to find tuples that are in one relation but not in the other
i.e R-S = tuples in R but not in S
Conditions
Both must have same arity(i.e the same columns)
Both should have the same domain(i.e same data types..)
Set difference(-)
Example
Set difference(-)
Example
Union(U)
It is like the union operation in SET theory
It is a binary operator( It requires two relations to perform an operation)
It is set of all objects that are members of A or B or both
It is denoted by U
The duplicate values will be eliminated
Two conditions
Both relations should have the same arity
Both should have the same domain
Union(U)
Union(U)
Union(U)
Cartesian Product(X)
Associates every tuple of first Relation(R1) with every tuple of second
relation(R2) by multiplication
It is a binary operator
It is denoted by X
i.e R1xR2= all possible pairing
Same attribute may appear in R1 and R2
There is ambiguity which can be solved by referring the columns with
their table names, that is table_name.column_name
Cartesian Product(X)
Example
Cartesian Product(X)
Example
Cartesian Product(X)
Example
Example
Cartesian Product(X)
Cartesian Product(X)
Example
Rename(ρ)
It is a unary operator
It is denoted by ρ
Since the results of a relation algebra do not have a name
It is useful to giving them names
i.E ρ x E
The attributes formed by relational algebra can be given new names.
Example
Rename(ρ)
Set Intersection(n)
It like intersection operation in SET theory
It is a binary operator
It is denoted by n
Set Intersection(n)
Example
Join Operation
Join operation = Cartesian product+ selection process
It joins two tuples from different relations, if and only if the coditionis
satisfied

Inner join
will have only those tuples that satisfy the matching criteria are included
It discards row(s) of either table that do not match any row of the other
table
Inner join
Types of inner join
1. Theta join()
2. Equi join()
3. Natural join()
Theta join()
A general case of join operation
Also called conditional join
Denoted by
Used to join two or more relations on some conditions
θ is a predicate
Conditional operators: : =,<,>, ≤,≥,and ≠
Theta join()
Equi join
A special case of theta joini
Where it uses the equivalence condition
Conditional operator: =
Equi join
Example
Natural Join
A special case of equi join
Can be used if there is only a common attribute
The name and domain of the attributes must be the same
Does not use any comparison operator
Natural join= Cartesian product+ selection+ projection
Example
Natural Join
Division Operation(/)
Denoted by / or
Used for queries qhich involve the ‘all’ or ‘every’
R1/R2 = tuples of R1 associated with all tuples of R2
If and only if every attribute of R2 is present in R1
Example
Division Operation(/)
Outer join
The results include unmatched rows of one of the tables, or of both
tables
The matching is based on the join condition
Types of outer join
1. Left outer join
2. Right outer join
3. Full outer join
Outer join
The results include unmatched rows of one of the tables, or of both
tables
The matching is based on the join condition
Types of outer join
1. Left outer join(will have matching rows and unmatching rows from
the left relation)
2. Right outer join(will have matching rows and unmatching rows from
the right relation)
3. Full outer join(will have matching rows and unmatching rows from
both left and right relation)
Example
Outer join

You might also like