Relational Algebra in DBMS
Relational Algebra in DBMS
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)
Example 1
Example 2
Output - Selects tuples from Tutorials where the topic is 'Database' and 'author'
is guru99.
Example 3
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.
Example of Projection:
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active
Here, the projection of CustomerName and status will give
CustomerName Status
Google Active
Amazon Active
Apple Inactive
Alibaba Active
Example
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.
σ 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