Lecture 3 - Relational Algebra-Full
Lecture 3 - Relational Algebra-Full
Lecture 3 - Relational Algebra-Full
Preview
• Relational Algebra
• SELECT(σ)
• Projection(π)
• Rename (ρ)
• Union operation (υ)
• Set Difference (-)
• Intersection
• Cartesian product(X)
• Join Operations
• Inner Join
• Theta Join
• EQUI join
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 operations
to perform this action. SQL Relational algebra query
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.
Relational Operations
• Unary Relational Operations
• SELECT (symbol: σ)
• PROJECT (symbol: π)
• RENAME (symbol: ρ)
ρFinalYrStudents(SID,SName)(Students)
A∪B
• For a union operation to be valid, the following conditions must hold –
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.
Table A – B
column 1 column 2
1 2
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.
Table A ∩ B
column 1 column 2
1 1
Cartesian Product(X)
Cartesian Product in DBMS is an operation used 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. It is also called
Cross Product or Cross Join.
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
END OF PORTION FOR CT - I
Join Operations
A Join operation combines related tuples from different
relations, if and only if a given join condition is satisfied. It is
denoted by ⋈.
EMPLOYEE SALARY Operation:
(EMPLOYEE ⋈ SALARY)
EMP_CODE EMP_NAME EMP_CODE SALARY EMP_CODE EMP_NAME SALARY
1 John 1 DHAKA
1 John 1 DHAKA
2 Harry 2 DELHI 2 Harry 2 DELHI
3 Jackson 3 NEW YORK 3 Harry 3 NEW
YORK
Outer Join
Outer Join in Relational algebra returns all the attributes of both the table
depending on the condition. If some attribute value is not present for any one
of the tables it returns NULL in the respective row of the table attribute.
EMPLOYEE WORKERS Output
EMP_NAME STREET CITY EMP_NAME BRANCH SALARY EMP_NAME STREET CITY BRANCH SALAR
Y
Ram Civil line Mumbai Ram Infosys 10000 Ram Civil line Mumbai Infosys 10000
Ravi M.G. Street Delhi Shyam Park street Kolkata Wipro 20000
Kuber HCL 30000
Shyam Park street Kolkata Shyam Wipro 20000 Park street Kolkata
Shyam Wipro 20000
It is denoted by ⟗.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: