Relational Algebra and SQL: Dr. Ghulam Mustafa
Relational Algebra and SQL: Dr. Ghulam Mustafa
Relational Algebra and SQL: Dr. Ghulam Mustafa
CSC 220
Outline
1 Relational Algebra
Relational Algebra
The Select Operation
2 Projection
Projection
3 Union
Union
4 Practice
5 Intersection
6 Set-difference
7 Renaming
8 Quiz
9 Takeaway!
Dr. Ghulam Mustafa (BULC) Week6 March 19, 2019 2 / 40
Relational Algebra Relational Algebra
Relational Algebra
Outline
1 Relational Algebra
Relational Algebra
The Select Operation
2 Projection
Projection
3 Union
Union
4 Practice
5 Intersection
6 Set-difference
7 Renaming
8 Quiz
9 Takeaway!
Dr. Ghulam Mustafa (BULC) Week6 March 19, 2019 4 / 40
Relational Algebra The Select Operation
Scenario-1
Scenario1-Solution
Find movies made by Hanson after 1997. What will be the output of
following?
Scenario1-Solution
Find movies made by Hanson after 1997. What will be the output of
following?
Scenario2
Scenario3-Table
Scenario3
Outline
1 Relational Algebra
Relational Algebra
The Select Operation
2 Projection
Projection
3 Union
Union
4 Practice
5 Intersection
6 Set-difference
7 Renaming
8 Quiz
9 Takeaway!
Dr. Ghulam Mustafa (BULC) Week6 March 19, 2019 14 / 40
Projection Projection
Projection
Example
Find all movies and their ratings
Scenario4-Table
Select ID, name, salary from relation "instructor"?
Scenario4-Table
The term select in relational algebra has a different meaning than the
one used in SQL, which is an unfortunate historical fact.
In relational algebra, the term select corresponds to what we refer to
in SQL as where.
Similarly, Project corresponds to Select in SQL
Scenario5-Table
Scenario5-Solution
Practice
Outline
1 Relational Algebra
Relational Algebra
The Select Operation
2 Projection
Projection
3 Union
Union
4 Practice
5 Intersection
6 Set-difference
7 Renaming
8 Quiz
9 Takeaway!
Dr. Ghulam Mustafa (BULC) Week6 March 19, 2019 24 / 40
Union Union
Union
Example
Practice
Practice
Union
Intersection
Example
Set-difference
Example
Renaming
Practice
Solution
Practice
Quiz
1 Relational Algebra
Relational Algebra
The Select Operation
2 Projection
Projection
3 Union
Union
4 Practice
5 Intersection
6 Set-difference
7 Renaming
8 Quiz
9 Takeaway!
Takeaway!