Analysis and Design of Data Systems. Relational Algebra 2 (Lecture 18)

Слайд 2

A B A B A B UNION MINUS INTERSECTION Set Operations

A B

A B

A B

UNION

MINUS

INTERSECTION

Set Operations UNION, INTERSECTION, MINUS

The next group of relational

algebra operations are the standard mathematical operations on sets.
Слайд 3

Set Operations UNION, INTERSECTION, MINUS UNION, INTERSECTION, and MINUS are binary

Set Operations UNION, INTERSECTION, MINUS

UNION, INTERSECTION, and MINUS are binary operations.

 

This means

that the two relations have the same number of attributes and each corresponding pair of attributes has the same domain.
Слайд 4

UNION Example: Retrieve the Social Security numbers of all employees who

UNION

Example: Retrieve the Social Security numbers of all employees who either

work in department 5 or directly supervise an employee who works in department 5.

Step 1:

Step 2:

Step 3:

Step 4:

or, as a single relational algebra expression:

Set operations eliminate duplicates

Слайд 5

Set operations (attributes naming)

Set operations (attributes naming)

 

 

 

 

Слайд 6

CARTESIAN PRODUCT Operation (CROSS PRODUCT) Cartesian product operation produces a new

CARTESIAN PRODUCT Operation (CROSS PRODUCT)

 

Cartesian product operation produces a new element by

combining every tuple from one relation with every tuple from the other relation.

 

The CARTESIAN PRODUCT operation by itself is generally meaningless, except when followed by a selection that matches values of attributes coming from the component relations.

Слайд 7

CARTESIAN PRODUCT Operation Example: retrieve a list of names of each

CARTESIAN PRODUCT Operation

Example: retrieve a list of names of each female

employee’s dependents

Step 1:

Step 2:

Step 3:

Step 4:

Step 5:

Step 1:

Resulting Relations:

Слайд 8

CARTESIAN PRODUCT Operation Step 2: Step 3:

CARTESIAN PRODUCT Operation

Step 2:

Step 3:

Слайд 9

CARTESIAN PRODUCT Operation Step 4: Step 5: Because this sequence of

CARTESIAN PRODUCT Operation

Step 4:

Step 5:

Because this sequence of CARTESIAN PRODUCT followed

by SELECT is quite commonly used to combine related tuples from two relations, a special operation, called JOIN, was created to specify this sequence as a single operation.
Слайд 10

Example: retrieve the name of the manager of each department. SELECT

 

 

Example: retrieve the name of the manager of each department.

SELECT d.Dname,

e.Fname, e.Lname
FROM EMPLOYEE e, DEPARTMENT d
WHERE Ssn = Mgr_ssn;
Слайд 11

where is of the form: AND AND … AND (condition)

 

 

 

where is of the form:
AND AND

… AND (condition)