Chapter 3 - Relational Data Model _ 1
Chapter 3 - Relational Data Model _ 1
R 𝚹𝚹 S = 𝚷all (𝞼 𝚹 (R X S))
• The general form of theta join is:
= S = 𝚷all (𝞼 = (R X S))
• The general form of equi join is:
R
- Degree (Result) = Degree (R) + Degree (S)
- Cardinality (Result) <= Cardinality(R) X
Cardinality(S)
Equi Join
Natural Join
• To perform natural join on two relations, they should
contain at least one common attributes.
• It is just like the equi join with the elimination of the
common attributes.
• The natural join is denoted by ( ) symbol
S = 𝚷all (R S)
represented as:
R
Natural Join
Outer Join
• It is an extension of the natural join operation to deal
with the missing information.
• The outer join consists of two steps:
- First, a natural join is executed
- Then if any record in one relation does not match a
record from the other relation in the natural join, that
unmatched record is added to the join relation, and the
additional columns are filled with NULLs
• The different types of outer join are:
- Left Outer Join
- Right Outer Join
Left Outer Join
R 𝚹 R = 𝚷all (𝞼 𝚹 (R X R))
• The general form of self join
𝞹empNo ( 𝞼projectNo=‘comp01’(Assigned_To))
project ’comp01’
𝞹 empNo,name (𝞼 projectNo=‘comp01’(Emp
project ’comp01’
Assigned_To))
Relational Algebra Query
Emp(empNo,name)
Project(projectNo,pName,manager)
Assigned_To(projectNo,empNo)
Query: Find empNo of employees working on
project ’comp01’
Query: Find details of employees working on
project ’comp01’
Query: Find the empNo who don’t work on
project ’comp01’
Relational Algebra Query
• Query: Obtain the details of employees working
Project))
• Query: Find the details of employees working
Assigned_To))
Relational Algebra Query
(Assigned_To))
OR
Sailors))
Sailors)
Query: Find the sailor ids of the sailors who’ve
𝞹 shipment_no (𝞼 weight>20pound(Shipment))
shipments weighing over 20 pounds
Relational Algebra Query
Query: Find the names of customers with more
𝞹 cust_name (𝞼 annual_revenue>$10million(Customer))
than $10 million in annual revenue
𝞹 driver_name (𝞼 truckno=45(Truck))
Query : Find the driver of truck 45
𝞹 cust_name,annual_revenue (𝞼
over 100 pounds
weight>100pounds(Customer Shipment))
Query: Find the truck numbers of trucks which
have carried shipments weighing over 100
𝞹 truckno (𝞼 weight>100pounds(Shipment))
pounds
Relational Algebra Query
Query: Find the names of drivers who have
𝞹 driver_name (𝞼 weight>100pounds(Shipment
delivered shipments weighing over 100 pounds
Truck))
𝞹 destination_city (𝞼 annual_revenue>$15million(Customer
million in annual revenue
Shipment))
Relational Algebra Query
Query: List the customers having over $5 million
in annual revenue who have sent shipments
𝞹 cust_name (𝞼 annual_revenue>$5million(Customer)
weighing greater than 1 pound
𝞼 weight>1pound (Shipment))
Query: List the customers whose shipments have
𝞹 cust_name (𝞼 driver_name=‘Ramesh’(Customer
been delivered by truck driver Ramesh
Shipment Truck))
Relational Algebra Query
Query: Find the customers having over $5 million in
annual revenue who have sent shipments
weighing less than 1 pound or have sent a
𝞹 cust_name (𝞼 annual_revenue>$5million(Customer)
shipment to Bhubaneswar
𝞼 population>500000(City))
city (
Relational Algebra Query
Query: List the drivers who have delivered
shipments for customers with annual revenue
over $20 million to cities with population over 1
𝞹 city_name (City)
Question
Consider the COMPANY database schema:
Employee (ssn, fname, lname, bdate, address,
gender, salary, super_ssn, dno)
Department (dno, dname, mgr_ssn,
mgr_start_date)
Dept_Location (dno, dloc)
Project (pno, pname, plocation, dno)
Works_On (essn, pno, hours)
Dependent (essn, dependent_name, gender, bdate,
relationship)
Question
a. List the names of all employees who have a
dependent with the same first name as
themselves.
𝞹 lname, fname
(Employee fname=dependent name AND
ssn=essn (Dependent))
emp_all_proj)
d. Retrieve the average salary of all female
g (𝞼
employees.
(Employee ))
Question
e. List the last names of department managers who