Relational Algebra Overview These operations enable a user to specify basic retrievel requests (Queries) The result of these operation is a new relation
Select operation Select the employee tuples whose department number is 4: (employee) (The number of columns) = (The number of columns) employee (The number of tubles (rows) staisfies the condition) Select the employee tuples whose salary is greater than 30000 (employee) (The number of columns) = (The number of columns) employee (The number of tubles (rows) staisfies the condition)
Select operation (More than one condition) (employee) (employee) Employee Table Eno Ename Dno Salary 4 35000 4 25000 3 30000 2 20000 -
Select operation (Complex) Employee working Dno=4 and got salary >30000 or Dno=4 and got salary <20000 (employee)
Project Operation To list each employee’s first and last name and salary from employee table (Employee) To list each employee’s snn , salary and address from employee table (Employee) snn salary address snn salary address -- -- -- <=
Select and project operations For employees working in Dno=5, list F n ame, ssn, salary Select project (employee). (all columns in emplyee table , the rows scatisfy the condition) ( ) (all rwos in table , the list columns(Fname,ssn,salary))
Union operation Including a ll tubles that are either in R or in S or in both R and S Duplicate tubles are eliminated Two conditions 1- R and S have the same number of attributes 2- Each pair of coresponding attributes in R and S have the same data type
Union operation Example1
Union operation Example2
Intersection operation R A ll tuples that are in both R and S
Difference operation R I ncludes all tuples that are in R but not in S
Join operation Campine related tuples from various relations
Join operation example1
Join operation example2 Suppose that we want to retrieve the name of the manager of each department Department.MGRSSN = Employee.SSN
EXAMPLE2
Join operation example3 Suppose that we want to retrieve the name of the project and name of the controlling department
Join operation example 4 Suppose that we want to retrieve the name of the employee and names of the projects that worked on
Natural join R equires the two join attributes have the same name in both relations.