CIS340 - Lecture Algebra-1
CIS340 - Lecture Algebra-1
The
Relational
Algebra and
Relational
Calculus
شرائح العرض: تنبيه
) هي وسيلةSlides(
لتوضيح الدرس واداة من
.االدوات في ذلك
DNO = 4 (EMPLOYEE)
Select the employee tuples whose salary is greater than $30,000:
SALARY > 30,000 (EMPLOYEE)
Sequence of operations:
DEP5_EMPS
Result
We can use the UNION operation as follows:
DEP5_EMPS DNO=5 (EMPLOYEE)
RESULT1 SSN(DEP5_EMPS)
Result1 has the SSN of all employees who work in
department 5
RESULT2(SSN) SUPERSSN(DEP5_EMPS)
Result 2 has the SSN of all employees who directly
supervise an employee who works in department 5
RESULT RESULT1 RESULT2
The union operation produces the tuples that are in either
RESULT1 or RESULT2 or both
Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Slide 6- 24
Example of the result of a UNION
operation
UNION Example
FEMALE_EMPS
EMPNAMES
EMP_DEPENDENTS
Chapt
er 6-38
Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe
Example of applying CARTESIAN
PRODUCT
R A B S C D
a 1 1 x
b 2 1 y
3 z
R S
B=C
Q A B C D
a 1 1 x
a 1 1 y
Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Chapter 6-41
Binary Relational Operations: JOIN (cont.)
Example: Suppose that we want to retrieve the name of the
manager of each department.
To get the manager’s name, we need to combine each
DEPARTMENT tuple with the EMPLOYEE tuple whose SSN
value matches the MGRSSN value in the department tuple.
We do this by using the join operation.
DEPT_MGR DEPARTMENT MGRSSN=SSN EMPLOYEE
MGRSSN=SSN is the join condition
Combines each department record with the employee who
manages the department
The join condition can also be specified as
DEPARTMENT.MGRSSN= EMPLOYEE.SSN