SlideShare a Scribd company logo
1 of 67
Download to read offline
Relational
Algebra
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
•Two formal language for the relational model
(a)Relational Algebra
(b)Relational calculus
prepared by Visakh V,Assistant Professor,
LBSITW
• Basic set of operation for the relational model.
• These operation enable a user to specify basic
retrieval requests.
• The result of a retrieval is a new relation, which
can be further manipulated using operations of
same algebra.
prepared by Visakh V,Assistant Professor,
LBSITW
•it is important for several reasons:
 provides formal foundation
for relational model
 used as basis for
implementing and optimizing
queries in RDMS
 Some of its concepts are
incorporated into SQL Standard
query language for RDMS
prepared by Visakh V,Assistant Professor,
LBSITW
No commercial RDBMS in use today
provides an interface for the relational
queries.
•Relational algebra operations can be divided into
UNION
INTERSECTION
SET DIFFERENCE
CARTESIAN PRODUCT
SELECT
PROJECT
JOIN etc.
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
s
p
:Operate on a single relation
prepared by Visakh V,Assistant Professor,
LBSITW
s
prepared by Visakh V,Assistant Professor,
LBSITW
Syntax :
s <selection condition> (R)
<selection condition> is made up of number of clauses of the form
<attribute name > <comparison op> <attribute name>
OR
<attribute name > <comparison op> <constant value>
{ =,<,>,<=,>=,!= }
It select certain rows
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
Ex : s(DNO=5 ) (EMPLOYEE)
Ex : s(SALARY>25000) (EMPLOYEE)
Lets try. . .
prepared by Visakh V,Assistant Professor,
LBSITW
Clauses can be connected by the
Boolean operators and, or ,not to from a
general selection condition.
s(DNO=4 AND SALARY>25000) OR (DNO=5 AND SALARY>30000) (EMPLOYEE)
prepared by Visakh V,Assistant Professor,
LBSITW
SELECT operation is commutative :
s <cond1> ( s <cond2> (R)) = s <cond2> ( s <cond1> (R))
Cascade of SELECT operation:
s<cond1> ( s <cond2> (… ( s <condn> (R)). . . ))
=
( s <cond1> AND <cond2> AND . . . AND <condn> (R)
prepared by Visakh V,Assistant Professor,
LBSITW
p
prepared by Visakh V,Assistant Professor,
LBSITW
Syntax :
p <attribute list > (R)
It select certain columns
Duplicate elimination : it removes any duplicate
tuples , and we get a valid relation .
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
•pSEX, SALARY(EMPLOYEE)
•pLname,Fname,SALARY(EMPLOYEE)
Where is the
resultant table ???
prepared by Visakh V,Assistant Professor,
LBSITW
Duplicate
elimination
pFNAME, LNAME, SALARY(sDNO=5(EMPLOYEE))
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
We can write the operations as a single algebra
expression by nesting the operation
or
we can apply one operation at a time and create
intermediate result relations.
pFNAME, LNAME, SALARY(sDNO=5(EMPLOYEE))
Can replace with
DEPCS2  sDNO=5(EMPLOYEE)
RESULT  pFNAME, LNAME, SALARY (DEPCS2)
prepared by Visakh V,Assistant Professor,
LBSITW
Renaming of attribute
TEMP  sDNO=5(EMPLOYEE)
R(FIRSTNAME,LASTNAME,SALARY) pFNAME, LNAME, SALARY (TEMP)
prepared by Visakh V,Assistant Professor,
LBSITW
A formal RENAME r(rho) operations:
• rename either relation name, attribute name or both
r (B1,B2,…Bn) (R)
r s (R)
r s(B1,B2,…Bn) (R)
S: new table name;
Bn: new attribute name
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
UNION
INTERSECTION
&
SET DIFFERENCE
prepared by Visakh V,Assistant Professor,
LBSITW
: R  S
: Include all tuples
:Duplicates are eliminated
: R  S
: include all tuples that are in both R & S
: R - S
: include all tuples that are in R but not in S
prepared by Visakh V,Assistant Professor,
LBSITW
Union compatible
(corresponding pair have same number
of attribute and same domain)
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
Example:
prepared by Visakh V,Assistant Professor,
LBSITW
Q. Retrieve the social security Number of
all employees who either work in
department 5 or directly supervise an
employee who works department 5.
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
•UNION and INTERSECTION are
commutative but SET
DIFFERENCE is not.
R  S =R  S – (R-S )-(S-R)
prepared by Visakh V,Assistant Professor,
LBSITW
• Also known as CROSS PRODUCT or CROSS JOIN
• Denoted by X
• syntax :
• tab1 X tab2
• also binary set operations.
• if A has m tuples and B has n tuples then A X B has m * n
tuples .
• Cartesian product followed by SELECT is used to identify
and select related tuples from two relation.
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
EMP_ID DESIGNATION SALARY
101 PROFESSOR 1,25000
102 ASSOCIATE PROF 90000
103 ASSISTANT PROF 40000
E_ID F_NAME M_NA
ME
L_NAME AGE
102 SURESH KUMAR S 43
103 SUMI M MOL 23
101 SHREELEKSHMI R S 40
TAB1
FIND salary ,name AND designation OF EACH EMPLOYEE?????
prepared by Visakh V,Assistant Professor,
LBSITW
DESIGNATIO
N
SALARY EMP_I
D
E_ID F_NAME M_NAME L_NAM
E
AGE
PROFESSOR 1,25000 101 102 SURESH KUMAR S 43
PROFESSOR 1,25000 101 103 SUMI M MOL 23
PROFESSOR 1.25000 101 101 SHREELEKSHMI R S 40
ASSOCIATE
PROF
90000 102 102 SURESH KUMAR S 43
ASSOCIATE
PROF
90000 102 103 SUMI M MOL 23
ASSOCIATE
PROF
90000 102 101 SHREELEKSHMI R S 40
ASSISTANT
PROF
40000 103 102 SURESH KUMAR S 43
ASSISTANT
PROF
40000 103 103 SUMI M MOL 23
ASSISTANT
PROF
40000 103 101 SHREELEKSHMI R S 40prepared by Visakh V,Assistant Professor,
LBSITW
DESIGNATI
ON
SALARY EMP_ID E_ID F_NAME M_NAME L_NAME AGE
PROFESSO
R
1.25000 101 101 SHREELEK
SHMI
R S 40
ASSOCIATE
PROF
90000 102 102 ANIL S GANESH 28
ASSISTANT
PROF
40000 103 103 SUMI M MOL 23
SALARY F_NAME M_NAME L_NAME DESIGNATION
1.25000 RAMESH R VINOD PROFESSOR
90000 ANIL S GANESH ASSOCIATE PROF
40000 SUNIL A NARAYAN ASSISTANT PROFprepared by Visakh V,Assistant Professor,
LBSITW
Write relational algebra expression
Retrieve a list of names of each
employee’s dependents.
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
• Combine related tuples from two relation into single
tuples.
• denoted by
• R <JOIN CONDITION> S .
• Consider example
RESULT EMPLOYEE X DEPENDENT
FINAL  sSSN= ESSN (RESULT)
The above can be replaced with
FINAL  EMPLOYEE SSN=ESSN DEPENDENT .prepared by Visakh V,Assistant Professor,
LBSITW
Retrieve the name of manager of
each department
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
• A general join condition is of the form
<condition>AND<condition>AND. . . AND <condition>
Each condition of the form
Ai Bi
ᶱ
Comparison operator {=,!=,<,>,<=,>=}
•A JOIN operation with such a
general join condition is
called a THETA JOIN
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
• The JOIN where the only comparison operator
used is ‘ = ‘
• It requires that two JOIN attributes have the same
name in both relation .
• if this is not the case then renaming operation done
first.
• This is basically an EQUIJOIN followed by removal of
unnecessary attributes
•Ex: DEPT_LOCS  DEPARTMENT * DEPT_LOCATIONS.
prepared by Visakh V,Assistant Professor,
LBSITW
Join attribute
prepared by Visakh V,Assistant Professor,
LBSITW
•A JOIN operation used to combine
data from multiple relations so that
related information can be presented
in a single table. This operations are
also known as inner joins.
prepared by Visakh V,Assistant Professor,
LBSITW
• Used when we want to keep all the tuples in R
• three main variation are
• LEFT OUTER JOIN
• RIGHT OUTER JOIN
• FULL OUTER JOIN
prepared by Visakh V,Assistant Professor,
LBSITW
• Relation instructor1
• Relation teaches1
ID course_id
10101
12121
76766
CS-101
APL-101
BIO-101
Comp. Sci.
Applied
PED
ID dept_name
10101
12121
15151
name
Sreejith
Suresh
Sreeja
prepared by Visakh V,Assistant Professor,
LBSITW
• Join
instructor teaches
ID dept_name
10101
12121
Comp. Sci.
Applied
course_id
CS-101
APL-201
name
Sreejith
Suresh
prepared by Visakh V,Assistant Professor,
LBSITW
 Left Outer Join
instructor teaches
ID dept_name
10101
12121
15151
Comp. Sci.
Applied
PED
course_id
CS-101
APL-201
null
name
Sreejith
Suresh
Sreeja
ID course_id
10101
12121
76766
CS-101
APL-101
BIO-101
Comp. Sci.
Applied
PED
ID dept_name
10101
12121
15151
name
Sreejith
Suresh
Sreeja
prepared by Visakh V,Assistant Professor,
LBSITW
 Right Outer Join
instructor teaches
ID dept_name
10101
12121
76766
Comp. Sci.
Applied
null
course_id
CS-101
APL-201
BIO-101
name
Sreejith
Suresh
null
ID course_id
10101
12121
76766
CS-101
APL-101
BIO-101
Comp. Sci.
Applied
PED
ID dept_name
10101
12121
15151
name
Sreejith
Suresh
Sreeja
prepared by Visakh V,Assistant Professor,
LBSITW
 Full Outer Join
instructor teaches
ID dept_name
10101
12121
15151
76766
Comp. Sci.
Applied
PED
null
course_id
CS-101
APL-201
null
BIO-101
name
Sreejith
Suresh
Sreeja
null
ID course_id
10101
12121
76766
CS-101
APL-101
BIO-101
Comp. Sci.
Applied
PED
ID dept_name
10101
12121
15151
name
Sreejith
Suresh
Sreeja
prepared by Visakh V,Assistant Professor,
LBSITW
Additional
• semi join
• left semi join.
• Right semi join:
Rno Name AGE
1 A 40
2 B 42
3 C 38
R_no Phone
1 9865321245
3 9764316598
5 9598946532
prepared by Visakh V,Assistant Professor,
LBSITW
•left semi join.
• Right semi join:
Rno Name AGE
1 Mahati 40
3 Meenu 38
R_no Phone
1 9865321245
3 9764316598
prepared by Visakh V,Assistant Professor,
LBSITW
•Denoted by 
prepared by Visakh V,Assistant Professor,
LBSITW
R S
prepared by Visakh V,Assistant Professor,
LBSITW
YEAR TOUR_PART_EM_ID
2003 1001
2004 1001
2013 1001
2008 1003
2009 1003
2008 1004
2004 1004
2011 1004
2003 1004
2003 1002
2004 1002
2011 1002
2013 1002
2012 1002
EMP_id NAME ADDRESS
1001 SURESH AAAA
1002 LALAN BBBB
1003 JC CCCC
1004 ANVAR DDDD
Retrieve the name &
address of employees who
participated in all tour that
‘Suresh ‘sir attended .
prepared by Visakh V,Assistant Professor,
LBSITW
Retrieve the names of employees who work on all
the project that ‘John Smith’ works on
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
prepared by Visakh V,Assistant Professor,
LBSITW
• allowing functions of attributes to be
included in the projection
•EX:
•pSALARY-DEDUCTION, SALARY * 0.25(sDNO=5(EMPLOYEE))
prepared by Visakh V,Assistant Professor,
LBSITW
• SUM
•AVERAGE
•MAXIMUM
•MINIMUM
•COUNT
•Aggregate function operation using the symbol
<grouping attribute> <function list>(R)
Calligraphic G
prepared by Visakh V,Assistant Professor,
LBSITW
a. r R(DNO,NO_OF_EMPLOYEES,AVERAGE_SAL) (Dno COUNT ssn, AVERAGE salary(EMPLOYEE))
b. Dno COUNT ssn, AVERAGE salary(EMPLOYEE)
c. COUNT ssn, AVERAGE salary(EMPLOYEE)
prepared by Visakh V,Assistant Professor,
LBSITW
Precedence of relational operators:
1.[SELECT, PROJECT, RENAME]
(highest).
2.[PRODUCT, JOIN].
3.INTERSECTION.
4.[UNION, --]
prepared by Visakh V,Assistant Professor,
LBSITW

More Related Content

What's hot (10)

Ch5a
Ch5aCh5a
Ch5a
 
Nfa vs dfa
Nfa vs dfaNfa vs dfa
Nfa vs dfa
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
Linear Classification
Linear ClassificationLinear Classification
Linear Classification
 
Lexical 2
Lexical 2Lexical 2
Lexical 2
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
AI Lesson 11
AI Lesson 11AI Lesson 11
AI Lesson 11
 
Ch6
Ch6Ch6
Ch6
 
Fun with lambda expressions
Fun with lambda expressionsFun with lambda expressions
Fun with lambda expressions
 
Normalization
NormalizationNormalization
Normalization
 

Similar to Relational algebra complete

Relational Algibra operation
Relational Algibra  operationRelational Algibra  operation
Relational Algibra operationUOB Quetta
 
Nested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypherNested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypheropenCypher
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational ModelHazemWaheeb1
 
Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationshindhe1098cv
 
Dbms ii mca-ch8-db design-2013
Dbms ii mca-ch8-db design-2013Dbms ii mca-ch8-db design-2013
Dbms ii mca-ch8-db design-2013Prosanta Ghosh
 

Similar to Relational algebra complete (6)

Relational Algibra operation
Relational Algibra  operationRelational Algibra  operation
Relational Algibra operation
 
Nested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypherNested subqueries and subquery chaining in openCypher
Nested subqueries and subquery chaining in openCypher
 
Intro to Relational Model
Intro to Relational ModelIntro to Relational Model
Intro to Relational Model
 
Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operation
 
SQL3.pdf
SQL3.pdfSQL3.pdf
SQL3.pdf
 
Dbms ii mca-ch8-db design-2013
Dbms ii mca-ch8-db design-2013Dbms ii mca-ch8-db design-2013
Dbms ii mca-ch8-db design-2013
 

More from Visakh V

Data base recovery
Data base recoveryData base recovery
Data base recoveryVisakh V
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms usersVisakh V
 
Transaction Management
Transaction Management Transaction Management
Transaction Management Visakh V
 
Memory Management
Memory ManagementMemory Management
Memory ManagementVisakh V
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keysVisakh V
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms usersVisakh V
 
Slide 6 er strong & weak entity
Slide 6 er  strong & weak entitySlide 6 er  strong & weak entity
Slide 6 er strong & weak entityVisakh V
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaVisakh V
 
Slide 2 data models
Slide 2 data modelsSlide 2 data models
Slide 2 data modelsVisakh V
 
Slide 1 introduction to dbms
Slide 1 introduction to dbmsSlide 1 introduction to dbms
Slide 1 introduction to dbmsVisakh V
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancyVisakh V
 
Relational algebr
Relational algebrRelational algebr
Relational algebrVisakh V
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by Visakh V
 

More from Visakh V (14)

Data base recovery
Data base recoveryData base recovery
Data base recovery
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
 
Transaction Management
Transaction Management Transaction Management
Transaction Management
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Slide 5 keys
Slide 5 keysSlide 5 keys
Slide 5 keys
 
Slide 4 dbms users
Slide 4 dbms usersSlide 4 dbms users
Slide 4 dbms users
 
Slide 6 er strong & weak entity
Slide 6 er  strong & weak entitySlide 6 er  strong & weak entity
Slide 6 er strong & weak entity
 
Slide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schemaSlide 3 data abstraction & 3 schema
Slide 3 data abstraction & 3 schema
 
Slide 2 data models
Slide 2 data modelsSlide 2 data models
Slide 2 data models
 
Slide 1 introduction to dbms
Slide 1 introduction to dbmsSlide 1 introduction to dbms
Slide 1 introduction to dbms
 
Data
DataData
Data
 
Functional dependancy
Functional dependancyFunctional dependancy
Functional dependancy
 
Relational algebr
Relational algebrRelational algebr
Relational algebr
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

Relational algebra complete

  • 1. Relational Algebra prepared by Visakh V,Assistant Professor, LBSITW
  • 2. prepared by Visakh V,Assistant Professor, LBSITW
  • 3. prepared by Visakh V,Assistant Professor, LBSITW
  • 4. •Two formal language for the relational model (a)Relational Algebra (b)Relational calculus prepared by Visakh V,Assistant Professor, LBSITW
  • 5. • Basic set of operation for the relational model. • These operation enable a user to specify basic retrieval requests. • The result of a retrieval is a new relation, which can be further manipulated using operations of same algebra. prepared by Visakh V,Assistant Professor, LBSITW
  • 6. •it is important for several reasons:  provides formal foundation for relational model  used as basis for implementing and optimizing queries in RDMS  Some of its concepts are incorporated into SQL Standard query language for RDMS prepared by Visakh V,Assistant Professor, LBSITW
  • 7. No commercial RDBMS in use today provides an interface for the relational queries. •Relational algebra operations can be divided into UNION INTERSECTION SET DIFFERENCE CARTESIAN PRODUCT SELECT PROJECT JOIN etc. prepared by Visakh V,Assistant Professor, LBSITW
  • 8. prepared by Visakh V,Assistant Professor, LBSITW
  • 9. s p :Operate on a single relation prepared by Visakh V,Assistant Professor, LBSITW
  • 10. s prepared by Visakh V,Assistant Professor, LBSITW
  • 11. Syntax : s <selection condition> (R) <selection condition> is made up of number of clauses of the form <attribute name > <comparison op> <attribute name> OR <attribute name > <comparison op> <constant value> { =,<,>,<=,>=,!= } It select certain rows prepared by Visakh V,Assistant Professor, LBSITW
  • 12. prepared by Visakh V,Assistant Professor, LBSITW
  • 13. Ex : s(DNO=5 ) (EMPLOYEE) Ex : s(SALARY>25000) (EMPLOYEE) Lets try. . . prepared by Visakh V,Assistant Professor, LBSITW
  • 14. Clauses can be connected by the Boolean operators and, or ,not to from a general selection condition. s(DNO=4 AND SALARY>25000) OR (DNO=5 AND SALARY>30000) (EMPLOYEE) prepared by Visakh V,Assistant Professor, LBSITW
  • 15. SELECT operation is commutative : s <cond1> ( s <cond2> (R)) = s <cond2> ( s <cond1> (R)) Cascade of SELECT operation: s<cond1> ( s <cond2> (… ( s <condn> (R)). . . )) = ( s <cond1> AND <cond2> AND . . . AND <condn> (R) prepared by Visakh V,Assistant Professor, LBSITW
  • 16. p prepared by Visakh V,Assistant Professor, LBSITW
  • 17. Syntax : p <attribute list > (R) It select certain columns Duplicate elimination : it removes any duplicate tuples , and we get a valid relation . prepared by Visakh V,Assistant Professor, LBSITW
  • 18. prepared by Visakh V,Assistant Professor, LBSITW
  • 19. •pSEX, SALARY(EMPLOYEE) •pLname,Fname,SALARY(EMPLOYEE) Where is the resultant table ??? prepared by Visakh V,Assistant Professor, LBSITW
  • 21. prepared by Visakh V,Assistant Professor, LBSITW
  • 22. We can write the operations as a single algebra expression by nesting the operation or we can apply one operation at a time and create intermediate result relations. pFNAME, LNAME, SALARY(sDNO=5(EMPLOYEE)) Can replace with DEPCS2  sDNO=5(EMPLOYEE) RESULT  pFNAME, LNAME, SALARY (DEPCS2) prepared by Visakh V,Assistant Professor, LBSITW
  • 23. Renaming of attribute TEMP  sDNO=5(EMPLOYEE) R(FIRSTNAME,LASTNAME,SALARY) pFNAME, LNAME, SALARY (TEMP) prepared by Visakh V,Assistant Professor, LBSITW
  • 24. A formal RENAME r(rho) operations: • rename either relation name, attribute name or both r (B1,B2,…Bn) (R) r s (R) r s(B1,B2,…Bn) (R) S: new table name; Bn: new attribute name prepared by Visakh V,Assistant Professor, LBSITW
  • 25. prepared by Visakh V,Assistant Professor, LBSITW
  • 26. UNION INTERSECTION & SET DIFFERENCE prepared by Visakh V,Assistant Professor, LBSITW
  • 27. : R  S : Include all tuples :Duplicates are eliminated : R  S : include all tuples that are in both R & S : R - S : include all tuples that are in R but not in S prepared by Visakh V,Assistant Professor, LBSITW
  • 28. Union compatible (corresponding pair have same number of attribute and same domain) prepared by Visakh V,Assistant Professor, LBSITW
  • 29. prepared by Visakh V,Assistant Professor, LBSITW
  • 30. prepared by Visakh V,Assistant Professor, LBSITW
  • 31. Example: prepared by Visakh V,Assistant Professor, LBSITW
  • 32. Q. Retrieve the social security Number of all employees who either work in department 5 or directly supervise an employee who works department 5. prepared by Visakh V,Assistant Professor, LBSITW
  • 33. prepared by Visakh V,Assistant Professor, LBSITW
  • 34. •UNION and INTERSECTION are commutative but SET DIFFERENCE is not. R  S =R  S – (R-S )-(S-R) prepared by Visakh V,Assistant Professor, LBSITW
  • 35. • Also known as CROSS PRODUCT or CROSS JOIN • Denoted by X • syntax : • tab1 X tab2 • also binary set operations. • if A has m tuples and B has n tuples then A X B has m * n tuples . • Cartesian product followed by SELECT is used to identify and select related tuples from two relation. prepared by Visakh V,Assistant Professor, LBSITW
  • 36. prepared by Visakh V,Assistant Professor, LBSITW
  • 37. EMP_ID DESIGNATION SALARY 101 PROFESSOR 1,25000 102 ASSOCIATE PROF 90000 103 ASSISTANT PROF 40000 E_ID F_NAME M_NA ME L_NAME AGE 102 SURESH KUMAR S 43 103 SUMI M MOL 23 101 SHREELEKSHMI R S 40 TAB1 FIND salary ,name AND designation OF EACH EMPLOYEE????? prepared by Visakh V,Assistant Professor, LBSITW
  • 38. DESIGNATIO N SALARY EMP_I D E_ID F_NAME M_NAME L_NAM E AGE PROFESSOR 1,25000 101 102 SURESH KUMAR S 43 PROFESSOR 1,25000 101 103 SUMI M MOL 23 PROFESSOR 1.25000 101 101 SHREELEKSHMI R S 40 ASSOCIATE PROF 90000 102 102 SURESH KUMAR S 43 ASSOCIATE PROF 90000 102 103 SUMI M MOL 23 ASSOCIATE PROF 90000 102 101 SHREELEKSHMI R S 40 ASSISTANT PROF 40000 103 102 SURESH KUMAR S 43 ASSISTANT PROF 40000 103 103 SUMI M MOL 23 ASSISTANT PROF 40000 103 101 SHREELEKSHMI R S 40prepared by Visakh V,Assistant Professor, LBSITW
  • 39. DESIGNATI ON SALARY EMP_ID E_ID F_NAME M_NAME L_NAME AGE PROFESSO R 1.25000 101 101 SHREELEK SHMI R S 40 ASSOCIATE PROF 90000 102 102 ANIL S GANESH 28 ASSISTANT PROF 40000 103 103 SUMI M MOL 23 SALARY F_NAME M_NAME L_NAME DESIGNATION 1.25000 RAMESH R VINOD PROFESSOR 90000 ANIL S GANESH ASSOCIATE PROF 40000 SUNIL A NARAYAN ASSISTANT PROFprepared by Visakh V,Assistant Professor, LBSITW
  • 40. Write relational algebra expression Retrieve a list of names of each employee’s dependents. prepared by Visakh V,Assistant Professor, LBSITW
  • 41. prepared by Visakh V,Assistant Professor, LBSITW
  • 42. • Combine related tuples from two relation into single tuples. • denoted by • R <JOIN CONDITION> S . • Consider example RESULT EMPLOYEE X DEPENDENT FINAL  sSSN= ESSN (RESULT) The above can be replaced with FINAL  EMPLOYEE SSN=ESSN DEPENDENT .prepared by Visakh V,Assistant Professor, LBSITW
  • 43. Retrieve the name of manager of each department prepared by Visakh V,Assistant Professor, LBSITW
  • 44. prepared by Visakh V,Assistant Professor, LBSITW
  • 45. • A general join condition is of the form <condition>AND<condition>AND. . . AND <condition> Each condition of the form Ai Bi ᶱ Comparison operator {=,!=,<,>,<=,>=} •A JOIN operation with such a general join condition is called a THETA JOIN prepared by Visakh V,Assistant Professor, LBSITW
  • 46. prepared by Visakh V,Assistant Professor, LBSITW
  • 47. • The JOIN where the only comparison operator used is ‘ = ‘ • It requires that two JOIN attributes have the same name in both relation . • if this is not the case then renaming operation done first. • This is basically an EQUIJOIN followed by removal of unnecessary attributes •Ex: DEPT_LOCS  DEPARTMENT * DEPT_LOCATIONS. prepared by Visakh V,Assistant Professor, LBSITW
  • 48. Join attribute prepared by Visakh V,Assistant Professor, LBSITW
  • 49. •A JOIN operation used to combine data from multiple relations so that related information can be presented in a single table. This operations are also known as inner joins. prepared by Visakh V,Assistant Professor, LBSITW
  • 50. • Used when we want to keep all the tuples in R • three main variation are • LEFT OUTER JOIN • RIGHT OUTER JOIN • FULL OUTER JOIN prepared by Visakh V,Assistant Professor, LBSITW
  • 51. • Relation instructor1 • Relation teaches1 ID course_id 10101 12121 76766 CS-101 APL-101 BIO-101 Comp. Sci. Applied PED ID dept_name 10101 12121 15151 name Sreejith Suresh Sreeja prepared by Visakh V,Assistant Professor, LBSITW
  • 52. • Join instructor teaches ID dept_name 10101 12121 Comp. Sci. Applied course_id CS-101 APL-201 name Sreejith Suresh prepared by Visakh V,Assistant Professor, LBSITW
  • 53.  Left Outer Join instructor teaches ID dept_name 10101 12121 15151 Comp. Sci. Applied PED course_id CS-101 APL-201 null name Sreejith Suresh Sreeja ID course_id 10101 12121 76766 CS-101 APL-101 BIO-101 Comp. Sci. Applied PED ID dept_name 10101 12121 15151 name Sreejith Suresh Sreeja prepared by Visakh V,Assistant Professor, LBSITW
  • 54.  Right Outer Join instructor teaches ID dept_name 10101 12121 76766 Comp. Sci. Applied null course_id CS-101 APL-201 BIO-101 name Sreejith Suresh null ID course_id 10101 12121 76766 CS-101 APL-101 BIO-101 Comp. Sci. Applied PED ID dept_name 10101 12121 15151 name Sreejith Suresh Sreeja prepared by Visakh V,Assistant Professor, LBSITW
  • 55.  Full Outer Join instructor teaches ID dept_name 10101 12121 15151 76766 Comp. Sci. Applied PED null course_id CS-101 APL-201 null BIO-101 name Sreejith Suresh Sreeja null ID course_id 10101 12121 76766 CS-101 APL-101 BIO-101 Comp. Sci. Applied PED ID dept_name 10101 12121 15151 name Sreejith Suresh Sreeja prepared by Visakh V,Assistant Professor, LBSITW
  • 56. Additional • semi join • left semi join. • Right semi join: Rno Name AGE 1 A 40 2 B 42 3 C 38 R_no Phone 1 9865321245 3 9764316598 5 9598946532 prepared by Visakh V,Assistant Professor, LBSITW
  • 57. •left semi join. • Right semi join: Rno Name AGE 1 Mahati 40 3 Meenu 38 R_no Phone 1 9865321245 3 9764316598 prepared by Visakh V,Assistant Professor, LBSITW
  • 58. •Denoted by  prepared by Visakh V,Assistant Professor, LBSITW
  • 59. R S prepared by Visakh V,Assistant Professor, LBSITW
  • 60. YEAR TOUR_PART_EM_ID 2003 1001 2004 1001 2013 1001 2008 1003 2009 1003 2008 1004 2004 1004 2011 1004 2003 1004 2003 1002 2004 1002 2011 1002 2013 1002 2012 1002 EMP_id NAME ADDRESS 1001 SURESH AAAA 1002 LALAN BBBB 1003 JC CCCC 1004 ANVAR DDDD Retrieve the name & address of employees who participated in all tour that ‘Suresh ‘sir attended . prepared by Visakh V,Assistant Professor, LBSITW
  • 61. Retrieve the names of employees who work on all the project that ‘John Smith’ works on prepared by Visakh V,Assistant Professor, LBSITW
  • 62. prepared by Visakh V,Assistant Professor, LBSITW
  • 63. prepared by Visakh V,Assistant Professor, LBSITW
  • 64. • allowing functions of attributes to be included in the projection •EX: •pSALARY-DEDUCTION, SALARY * 0.25(sDNO=5(EMPLOYEE)) prepared by Visakh V,Assistant Professor, LBSITW
  • 65. • SUM •AVERAGE •MAXIMUM •MINIMUM •COUNT •Aggregate function operation using the symbol <grouping attribute> <function list>(R) Calligraphic G prepared by Visakh V,Assistant Professor, LBSITW
  • 66. a. r R(DNO,NO_OF_EMPLOYEES,AVERAGE_SAL) (Dno COUNT ssn, AVERAGE salary(EMPLOYEE)) b. Dno COUNT ssn, AVERAGE salary(EMPLOYEE) c. COUNT ssn, AVERAGE salary(EMPLOYEE) prepared by Visakh V,Assistant Professor, LBSITW
  • 67. Precedence of relational operators: 1.[SELECT, PROJECT, RENAME] (highest). 2.[PRODUCT, JOIN]. 3.INTERSECTION. 4.[UNION, --] prepared by Visakh V,Assistant Professor, LBSITW