Relational Algebra in DBMS
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 )
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)
Output - Selects tuples from Tutorials where topic = 'Database'.
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
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.
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
Intersection
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.
Example:
A ∩ B
Table A ∩ B
column 1 column 2
1 1
Cartesian product(X)
This type of operation is helpful to merge columns from two relations.
Generally, a Cartesian product is never a meaningful operation when it performs
alone. However, it becomes meaningful when it is followed by other operations.
Example – Cartesian product
σ column 2 = '1' (A X B)
Output – The above example shows all rows from relation A and B whose
column 2 has value 1
σ column 2 = '1' (A X B)
column 1 column 2
1 1
1 1