Session 3 Welcome: To session 3-the 8th. learning sequence “Relational algebra “ Recap : In the previous learning sequence, we discussed some example queries. Present learning: We shall explore the following topic: - Another example Queries.
Relational Algebra
Relational Algebra A basic expression in the relational algebra consists of either one of the following: A relation in the database A constant relation
Relational Instances for the Purchasing System The Supplier relation: S-number S-name S-city S100 Ahmed Amman S200 Ali Jarash S300 Kasim Irbid S400 Jasim Aqaba S500 Rana
The Part relation: P-number P-name Color Price P-city P1 TV Silver 300 Amman P2 Camera Black 100 Jarash P3 Video 200 P4 PC 400 Irbid P5 Printer Red P6 Scanner silver 150 5
The shipment relation: S-number P-number Quantity S100 P1 100 P2 150 P3 200 P4 160 S200 S300 400 S400 80 S500 6
Q1- Get names of suppliers who supply at least one silver part.
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part)
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) P-number P-name Color Price P-city P1 TV Silver 300 Amman P4 PC 400 Irbid P6 Scanner silver 150 Jarash Temp1
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) Temp2 Shipment Temp1
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) Temp2 Shipment Temp1 S-number P-number Quantity P-name Color Price P-city S100 P1 100 TV Silver 300 Amman P4 160 PC 400 Irbid S200 200 S400 80 S500 Temp2
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) S-number S100 S200 S400 S500 Temp3
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3 S-number S-name S-city S100 Ahmed Amman S200 Ali Jarash S400 Jasim Aqaba S500 Rana Temp4
Q1- Get names of suppliers who supply at least one silver part. Temp1 P-color = ‘silver’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3 Result S-name (Temp4) S-name Ahmed Ali Jasim Rana Result
Q2- Get the names and cities of suppliers who supply parts stored in Irbid.
Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part)
Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) P-number P-name Color Price P-city P4 PC Silver 400 Irbid P5 Printer Red 100 Temp1
Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp2 S-number P-number Quantity P-name Color Price P-city S100 P4 160 PC Silver 400 Irbid P5 50 Printer Red 100 S400 80 S500
Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) S-number S100 S400 S500 Temp3
Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3
Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3 S-number S-name S-city S100 Ahmed Amman S400 Jasim Aqaba S500 Rana Temp4
Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3 Result S-name , S-city (Temp4)
Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Q2- Get the names and cities of suppliers who supply parts stored in Irbid. Temp1 P-city = ‘Irbid’ (Part) Temp2 Shipment Temp1 Temp3 S-number (Temp2) Temp4 Supplier Temp3 Result S-name , S-city (Temp4) S-name S-city Ahmed Amman Jasim Aqaba Rana Result
Q3- Find supplier names for suppliers who supply all parts.
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part)
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) P-number P1 P2 P3 P4 P5 P6 Temp1
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment)
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) S-number P-number S100 P1 P2 P3 P4 P5 P6 S200 S300 S400 S500 Temp2 S-number , P-number (Shipment) Temp2
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1 S-number S100 Temp3
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1 Temp4 Supplier Temp3
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1 Temp4 Supplier Temp3 Temp4 S-number S-name S-city S100 Ahmed Amman
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1 Temp4 Supplier Temp3 Result S-name (Temp4)
Q3- Find supplier names for suppliers who supply all parts. Temp1 P-number (Part) Temp2 S-number , P-number (Shipment) Temp3 Temp2 Temp1 Temp4 Supplier Temp3 Result S-name (Temp4) S-name Ahmed Result
Q4- How many parts they have?
Q4- How many parts they have? g count (P-number) (Part) P-number 7
Q5- Find the total quantities supplied by each supplier.
Q5- Find the total quantities supplied by each supplier. S-number g sum (Quantity) (Shipment)
Q5- Find the total quantities supplied by each supplier. S-number g sum (Quantity) (Shipment) S-number Quantity S100 610 S200 350 S300 400 S400 230 S500 100
Q5- Find the total quantities supplied by each supplier. S-number g sum (Quantity) as ( sum-quantity) (Shipment) S-number Sum-Quantity S100 730 S200 350 S300 400 S400 250 S500 100
Relational Algebra Summary: In this learning sequence, we discussed another example queries about purchasing system.
END