Chapter 5
Chapter 5
Example:
Projection:
Definition
Example:
The Selection and Projection operations extract information from only one
relation. There are obviously cases where we would like to combine information
from several relations.
Set Operations
Union, Set difference, Intersection, and Cartesian product are set operations
Union : R U S: The union of two relations R and S defines a relation that contains
all the tuples of R, or S, or both R and S, duplicate tuples being eliminated. R and S
must be union-compatible.
Imagine two tables, R and S, with I and J rows, respectively. To combine them into
a single table (union), we stack them on top of each other, creating a new table
with a maximum of (I + J) rows. For this to work, both tables must have the same
structure, meaning the same number of columns, and each pair of corresponding
columns must have the same type of data (domain). This is called being union-
compatible. Even if the column names are different, you can use the Projection
operation to align them, making the tables union-compatible.
Set difference
Intersection
The Intersection operation defines a relation consisting of the set of all tuples that
are in both R and S. R and S must be union-compatible
Cartesian product
Join operations
we want only combinations of the Cartesian product that satisfy certain
conditions and so we would normally use a Join operation instead of the Cartesian
product operation. The Join operation, which combines two relations to form a
new relation join operation is derived from cartesian product which is same as
performing selection operation with join predicate that means that only pair that
satisfy a condition are included. Join operation is difficult to efficiently operate
THETA JOIN
Theta join defines a relation that satisfy the predicate F in cartesian product .
predicate f is functional which returns the value in false and true.
Natural join
Natural join is used to fetch information which have same column and same
values in that columns
The Natural join is an Equijoin of the two relations R and S over all common
attributes x. The Natural join operation performs an Equijoin over all the
attributes in the two relations that have the same name. The degree of a Natural
join is the sum of the degrees of the relations R and S less the number of
attributes in x.
Outer join
In joining two relation there is one row (tuple) in relation (table) which doesn’t
have common values present and we want to fetch that data and display that in
table this will be accomplished by outer join. Missing values in tables are set as
null
a Left (natural) Outer join, as it keeps every tuple in the left-hand relation in the
result. Similarly, there is a Right Outer join that keeps every tuple in the right-
hand relation in the result. There is also a Full Outer join that keeps all tuples in
both relations, padding tuples with nulls when no matching tuples are found.
Semi join
A semi-join is an operation in relational databases that involves combining two
tables to retain only the rows from the first table that have matching values in the
second table One advantage of a Semi join is that it decreases the number of
tuples that need to be handled to form the join.
Division Operator
The Division operation defines a relation over the attributes C that consists of the
set of tuples from R that match the combination of every tuple in S.
Aggregation and Summation Operation
Retrieving some tuples and attributes summation and aggregation operators
In relational databases, an aggregate operation involves applying a function to a
set of values and producing a single summarized result. These functions operate
on a group of rows and are often used to perform calculations on data, such as
finding the sum, average, count, maximum, or minimum values within a specified
group
The main aggregate functions are:
COUNT – returns the number of values in the associated attribute.
SUM – returns the sum of the values in the associated attribute.
AVG – returns the average of the values in the associated attribute.
MIN – returns the smallest value in the associated attribute.
MAX – returns the largest value in the associated attribute.
Grouping operation:
Organizing data and categorizing based on certain criteria. The group by clause is
used to group the values and for grouping operations and it divides the table into
groups based on one or two columns they generate summaries
Summary of operations