2 Relational Algebra
2 Relational Algebra
1 2011 - 2012
Planning
2
Introduction
Example database
Relational algebra
Basic operation
Additional operation
Complex query
Introduction
3
Query Language
Data
DBMS
model
Disk
Introduction
4
Operation
Basic operations:
•Selection
•Projection
•Cross Product
•Union
•Different
•Rename
Additional operations:
•Intersection
•Join
•Division
Selection
Teacher
TID Tname DoB Degree Field #Dname
1 Sok Dara 01/01/85 Master Math Math
2 Sam Sambath 01/02/80 PhD Mechanic of fluid Mechanic
3 Sao Piseth 05/08/70 PhD Biology Environment
4 Tao Pisey 14/07/65 Engineer Electronic Electronic
5 Van Dany 08/12/87 Engineer hydropower Environment
Selection
Find out teacher who was born after 1985
Teacher
TID Tname DoB Degree Field #Dnam
1 Sok Dara 1985 Master Math Math
2 Sam Sambath 1980 PhD Mechanic of fluid Mechanic
3 Sao Piseth 1970 PhD Biology Environment
4 Tao Pisey 1965 Engineer Electronic Electronic
5 Van Dany 1987 Engineer hydropower Environment
Basic operation
12
Tname Field
Sok Dara Math
Sam Sambath Mechanic of fluid
Sao Piseth Biology
Tao Pisey Electronic
Van Dany hydropower
Basic operation
13
Degree
Master
PhD
Engineer
Basic operation
14
14
Teacher
TID Tname DoB Degree Field #Dnam
1 Sok Dara 01/01/85 Master Math Math
2 Sam Sambath 01/02/80 PhD Mechanic of fluid Mechanic
3 Sao Piseth 05/08/70 PhD Biology Environment
4 Tao Pisey 14/07/65 Engineer Electronic Electronic
5 Van Dany 08/12/87 Engineer hydropower Environment
Cross Product(RxS)
List all students’ name and the name of the course they
enroll in.
Course
CID Cname
StudentCourse
C1 Math
#StudentID #CID
C2 Physic
1 C1
Student 1 C2
StudentID Sname 2 C2
1 Chea Nary 2 C1
2 Sok Polin 3 C2
3 Yi Sophea
Basic operation
18
Teacher
TID Tname DoB Degree Field #Dnam
1 Sok Dara 01/01/85 Master Math Math
2 Sam Sambath 01/02/80 PhD Mechanic of fluid Mechanic
3 Sao Piseth 05/08/70 PhD Biology Environment
4 Tao Pisey 14/07/65 Engineer Electronic Electronic
5 Van Dany 08/12/87 Engineer hydropower Environment
Teacher1
TID Tname DoB Degree Field #Dnam
1 Sok Dara 01/01/85 Master Math Math
12 Nicole John 01/02/87 Master BD CS
3 Sao Piseth 05/08/70 PhD Biology Environment
14 Michael Jam 14/07/81 Engineer Electronic Electronic
Basic operation
20
Teacher U Teacher1
TID Tname DoB Degree Field #Dnam
1 Sok Dara 01/01/85 Master Math Math
2 Sam Sambath 01/02/80 PhD Mechanic of fluid Mechanic
3 Sao Piseth 05/08/70 PhD Biology Environment
4 Tao Pisey 14/07/65 Engineer Electronic Electronic
5 Van Dany 08/12/87 Engineer hydropower Environment
12 Nicole John 01/02/87 Master BD CS
14 Michael Jam 14/07/81 Engineer Electronic Electronic
Teacher – Teacher1
TID Tname DoB Degree Field #Dnam
2 Sam Sambath 01/02/80 PhD Mechanic of fluid Mechanic
4 Tao Pisey 14/07/65 Engineer Electronic Electronic
5 Van Dany 08/12/87 Engineer hydropower Environment
Additional operation
21
R1 R2 =
R1 R2 =
R1 R2 =
Additional operation
23
=
Additional operation
24
Equi-Join
Teacher (T) Children (C)
TID Tname DoB Degree Field #Dname #TID ChildName DoB
1 Sok Dara 01/01/1985 Master Math Math 1 Dan 01/01/2010
2 Sam Sambath 01/02/1980 PhD Mechanic of fluid Mechanic 1 Paul 01/02/2011
3 Sao Piseth 05/08/1970 PhD Biology Environment 2 Heng 09/08/2000
4 Tao Pisey 14/07/1965 Engineer Electronic Electronic 3 Lundi 08/08/1995
Join
List
all students’ name and the name of the course they
enroll in.
Course
CID Cname
StudentCourse
C1 Math
#StudentID #CID
C2 Physic
1 C1
Student 1 C2
StudentID Sname 2 C2
1 Chea Nary 2 C1
2 Sok Polin 3 C2
3 Yi Sophea
Additional operation
29
1 C1 1 C1
C1 Math
1 C2 1 C2
C2 Physic
2 C2 2 C1
2 C1 2 C2
3 C2 3 C1
3 C2
StudentCourse Course
=
StudentID
2
Additional operation
31