0% found this document useful (0 votes)
69 views

Lecture 7 - Relational Algebra in DBMS

The document discusses various relational algebra operations including selection (σ), projection (π), union (∪), set difference (-), and intersection (∩). Selection selects tuples that satisfy a given predicate. Projection eliminates all attributes except those in the projection list. Union includes all tuples that are in tables A or B after eliminating duplicates. Set difference includes tuples that are in A but not in B. Intersection includes tuples that are in both A and B.

Uploaded by

Njemax Panashe
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Lecture 7 - Relational Algebra in DBMS

The document discusses various relational algebra operations including selection (σ), projection (π), union (∪), set difference (-), and intersection (∩). Selection selects tuples that satisfy a given predicate. Projection eliminates all attributes except those in the projection list. Union includes all tuples that are in tables A or B after eliminating duplicates. Set difference includes tuples that are in A but not in B. Intersection includes tuples that are in both A and B.

Uploaded by

Njemax Panashe
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

CUIT201

DATA BASE SYSTEMS

RELATIONAL
ALGEBRA
Outline of Today’s Class
Relational Algebra in DBMS with Examples
•What is Relational Algebra?
•SELECT(σ)
•Projection(π)
•Union operation (υ)
•Set Difference (-)
•Intersection
•Cartesian product(X)
•Join Operations
•Inner Join:
•Theta Join:
•EQUI join:
•NATURAL JOIN (⋈)
•OUTER JOIN
•Left Outer Join(A B)
•Right Outer Join: ( A B )
•Full Outer Join: ( A B)
What is Relational Algebra?
• Relational algebra is a
widely used
procedural query language. It
collects instances of relations as input
and gives occurrences of relations as
output. It uses various operation to perform
this action.
• Relational algebra operations are performed
recursively on a relation. The output of these
operations is a new relation, which might be
formed from one or more input relations.
Basic Relational Algebra Operations

Relational Algebra devided in various groups


Unary Relational Operations
SELECT (symbol: σ)
PROJECT (symbol: π)
RENAME (symbol: )

Relational Algebra Operations From Set Theory


UNION (υ)
INTERSECTION ( ),
DIFFERENCE (-)
CARTESIAN PRODUCT ( x )
Basic Relational Algebra Operations

Binary Relational Operations


JOIN
DIVISION
SELECT (σ)
The SELECT operation is used for selecting a subset of the
tuples according to a given selection condition.
Sigma(σ)Symbol denotes it. It is used as an expression to
choose tuples which meet the selection condition. Select
operation selects tuples that satisfy a given predicate.

σp(r)

σ is the predicate

r stands for relation which is the name of the table

p is prepositional logic
Example 1

σ topic = "Database" (Tutorials)


SELECT (σ)
The SELECT operation is used for selecting a subset of the tuples
according to a given selection condition. Sigma(σ)Symbol denotes it.
It is used as an expression to choose tuples which meet the selection
condition. Select operation selects tuples that satisfy a given
predicate.

σp(r)

σ is the predicate

r stands for relation which is the name of the table

p is prepositional logic

Example 1

σ topic = "Database" (Tutorials)

Output - Selects tuples from Tutorials where topic = 'Database'.


SELECT (σ) cont’

Example 2

σ topic = "Database" and author = "guru99"( Tutorials)

Output - Selects tuples from Tutorials where the topic is


'Database' and 'author' is guru99.

Example 3

σ sales > 50000 (Customers)

Output - Selects tuples from Customers where sales is


greater than 50000
Projection(π)
The projection eliminates all attributes of the input relation
but those mentioned in the projection list. The projection
method defines a relation that contains a vertical subset of
Relation.
This helps to extract the values of specified attributes to
eliminates duplicate values. (pi) The symbol used to choose
attributes from a relation. This operation helps you to keep
specific columns from a relation and discards the other
columns.

Example of Projection:

Consider the following table


Projection(π) cont’
CustomerID CustomerName Status
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active

Here, the projection of CustomerName and status will give

Π CustomerName, Status (Customers)

CustomerName Status
Google Active
Amazon Active
Apple Inactive
Alibaba Active
Union operation (υ)

UNION is symbolized by ∪ symbol. It includes all tuples that are in tables A


or in B. It also eliminates duplicate tuples. So, set A UNION set B would be
expressed as:

The result <- A ∪ B

For a union operation to be valid, the following conditions must hold -

R and S must be the same number of attributes.


Attribute domains need to be compatible.
Duplicate tuples should be automatically removed.
Example

Consider the following tables.


Union operation (υ) cont’
Table A Table B
column 1 column 2 column 1 column 2

1 1 1 1
1 2 1 3

A ∪ B gives

Table A ∪ B

column 1 column 2

1 1
1 2
1 3
Set Difference (-)
- Symbol denotes it. The result of A - B, is a relation which includes all tuples
that are in A but not in B.

The attribute name of A has to match with the attribute name in B.


The two-operand relations A and B should be either compatible or Union
compatible.
It should be defined relation consisting of the tuples that are in relation A, but
not in B.
Table A - B
Example
A-B column 1 column 2

1 2
Intersection
- Symbol denotes it. The result of A - B, is a relation which includes all tuples
that are in A but not in B.

The attribute name of A has to match with the attribute name in B.


The two-operand relations A and B should be either compatible or Union
compatible.
It should be defined relation consisting of the tuples that are in relation A, but
not in B.

An intersection is defined by the symbol ∩


A∩B
Defines a relation consisting of a set of all tuple that are in both A and B.
However, A and B must be union-compatible.
Intersection cont’
Example:
A∩B

Table A ∩ B

column 1 column 2

1 1
Read other relational algebra stuff

You might also like