![Page 1: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/1.jpg)
UNIT 8RELATIONAL ALGEBRA
Computer Science
2019-2020
![Page 2: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/2.jpg)
Agenda
1. Base Operators
2. Set Operators
3. Advanced Operators
4. Conclusions
5. Questions
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 3: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/3.jpg)
0. Overview
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Table/Tables Operators of
Relational Algebra
New Table
Base Operators
• Restrict
• Project
• Join
Set Operators
• Union
• Intersection
• Difference
Advanced Operators
• Summirize
• Divide
![Page 4: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/4.jpg)
1. Base Operators. Restrict and Project
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The restrict and project operators produce an
output table that is a subset of an input table.
Restrict Project
Graphical Representation of Restrict and Project Operators
![Page 5: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/5.jpg)
1. Base Operators. Restrict and Project
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Restrict Project
condition or logical
expression to indicate
what rows should be
retained in the output
list of column names to
indicate what columns to
retain in the output
![Page 6: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/6.jpg)
1. Base Operators. Restrict and Project
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Sample Offering Table
Result of Restrict Operation on the Sample Offering Table
OfferDays = ‘MW’ AND OfferTerm = ‘SPRING’ AND OfferYear = 2006
![Page 7: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/7.jpg)
1. Base Operators. Restrict and Project
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Sample Offering Table
Result of Project Operation on the Sample Offering Table
Offering.CourseNumber
![Page 8: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/8.jpg)
1. Base Operators. Extended Cross Product Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The extended cross product operator:
can combine any two tables
can produce tables with excessive data
•an operator that builds a table consisting of all possible combinations of rows from each of the two input tables
The extended cross product
![Page 9: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/9.jpg)
1. Base Operators. Extended Cross Product Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Cross Product Example
![Page 10: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/10.jpg)
1. Base Operators. Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The join operator builds a new table by combining
rows from two tables that match on a join condition
The join condition specifies that two rows have an
identical value in one or more columns
• an operator that produces a table containing rows that match on a condition involving a column from each input table
The join
![Page 11: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/11.jpg)
1. Base Operators. Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Natural Join Example
![Page 12: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/12.jpg)
1. Base Operators. Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
In a natural join operation, the join
condition is equality (equi-join), one
of the join columns is removed, and
the join columns have the same
unqualified name
![Page 13: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/13.jpg)
1. Base Operators. Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The natural join operator consists of three steps:
A product operation to combine the rows.
A restrict operation to remove rows not satisfying the join condition.
A project operation to remove one of the join columns.
![Page 14: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/14.jpg)
1. Base Operators. Outer Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The result of a join operation includes the rows
matching on the join condition.
• an operator that provides the ability to preserve nonmatching rows in the result as well as to include the matching rows
The outer join
![Page 15: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/15.jpg)
1. Base Operators. Outer Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Outer Join Example
For nonmatching rows, null values
are used to complete the column
values in the other table
![Page 16: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/16.jpg)
1. Base Operators. Outer Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Ou
ter
Join
Op
era
tors The full outer
join
preserves nonmatching rows from both input
tables
The one-side outer join
produces the matching rows as well as the
nonmatching rows from the designated input
table
![Page 17: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/17.jpg)
1. Base Operators. Outer Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Full Outer Join Example
![Page 18: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/18.jpg)
1. Base Operators. Outer Join Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
One-Side Outer Join Example
![Page 19: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/19.jpg)
2. Set Operators.
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
The traditional set operators are used to determine:
all members of two sets - union
common members of two sets
- intersection
members unique to only one set
- difference
![Page 20: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/20.jpg)
2. Set Operators.
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
•retrieves all the rows in either table
•applied to two student tables at different universities can find all student rows.
A union operation
•retrieves just the common rows
•determine the students attending both universities
An intersection operation
•retrieves the rows in the first table but not in the second table
•determine the students attending only one university not in the second table
A difference operation
![Page 21: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/21.jpg)
2. Set Operators. Compatibility
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
With the table operators, both tables must be union
compatible because all columns are compared
• each table must have the same number of columns and each corresponding column must have a compatible data type
Union compatibility
![Page 22: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/22.jpg)
2. Set Operators. Examples
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 23: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/23.jpg)
2. Set Operators. Examples
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 24: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/24.jpg)
2. Set Operators. Examples
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 25: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/25.jpg)
3. Advanced Operators.Summarize Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Summarize is a powerful operator for decision making
Almost any kind of statistical function can be used to
summarize groups of rows.
• compresses a table by replacing groups of rows with individual rows containing calculated values.
• a statistical or aggregate function is used for the calculated values
The summarize operator
![Page 26: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/26.jpg)
3. Advanced Operators.Summarize Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Summarize Example
![Page 27: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/27.jpg)
3. Advanced Operators.Divide Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
In numerical division, the objective is to find how
many times one number contains another number.
In table division, the objective is to find values of one
column that contain every value in another column
•an operator that produces a table in which the values of a column from input table are associated with all the values from a column of a second input table
The divide operator
![Page 28: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/28.jpg)
3. Advanced Operators.Divide Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Divide vs Join Operator
• retrieve offerings taken by any student
join operator
• retrieve offerings taken by all (or every) students
divide operator
![Page 29: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/29.jpg)
3. Advanced Operators.Divide Operator
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
Divide Example
![Page 30: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/30.jpg)
4. Conclusions
The coverage of relational algebra groups the
operators into three categories:
the most widely used operators (restrict, project,
and join);
the extended cross product operator;
the more specialized operators include the
traditional set operators (union, intersection, and
difference) and advanced operators (summarize
and divide).
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 31: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/31.jpg)
4. Conclusions
Restrict (Select) - Extracts rows that satisfy a
specified condition;
Project - Extracts specified columns;
Product - Builds a table from two tables consisting of
all possible combinations of rows, one from each of
the two tables;
Union - Builds a table consisting of all rows
appearing in either of two tables;
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 32: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/32.jpg)
4. Conclusions
Intersect - Builds a table consisting of all rows
appearing in both of two specified tables;
Difference - Builds a table consisting of all rows
appearing in the first table but not in the second
table;
Join - Extracts rows from a product of two tables
such that two input rows contributing to any output
row satisfy some specified condition;
Outer join - Extracts the matching rows (the join part)
of two tables and the unmatched rows from one or
both tables;
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 33: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/33.jpg)
4. Conclusions
Divide - Builds a table consisting of all values of one
column of a binary (two-column) table that match (in
the other column) all values in a unary (one-column)
table;
Summarize - Organizes a table on specified grouping
columns. Specified aggregate computations are
made on each value of the grouping columns.
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 34: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/34.jpg)
5. Questions
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
![Page 35: UNIT 8 RELATIONAL ALGEBRA...1. Database Design, Application Development, and Administration by Michael V. Mannino// Published by McGraw-Hill/Irwin, a business unit of The McGraw-Hill](https://reader036.vdocuments.site/reader036/viewer/2022071403/60f771b6126d001fbb7f6be8/html5/thumbnails/35.jpg)
6. Useful to Read
Databases Systems - Anna Marchenko - Sumy State University - 2019-2020
1. Database Design, Application Development, and Administration by
Michael V. Mannino// Published by McGraw-Hill/Irwin, a business
unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the
Americas, New York, NY, 10020. Copyright © 2007 by The McGraw-
Hill Companies