Session 3 Welcome: To session 3 - the 7th. learning sequence “Relational algebra “ Recap : In the previous learning sequences, we discussed some operators of relational algebra. Present learning: We shall explore the following topic: - 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- Find The cities for all suppliers . S-city (Supplier)
Q1- Find The cities for all suppliers . S-city (Supplier) S-city Amman Jarash Irbid Aqaba The result relation
Q2- Find city for Ahmed.
Q2- Find city for Ahmed. Temp1 S-name = ‘Ahmed’ (Supplier)
Q2- Find city for Ahmed. Temp1 S-name = ‘Ahmed’ (Supplier) S-number S-name S-city S100 Ahmed Amman Temp1
Q2- Find city for Ahmed. Temp1 S-name = ‘Ahmed’ (Supplier) S-number S-name S-city S100 Ahmed Amman Temp1 Result S-city (Temp1) S-city Amman Result
Q3- Find the number and name for suppliers in Amman.
Q3- Find the number and name for suppliers in Amman. Temp1 S-city= ‘Amman’ (Supplier)
Q3- Find the number and name for suppliers in Amman. Temp1 S-city= ‘Amman’ (Supplier) S-number S-name S-city S100 Ahmed Amman S500 Rana Temp1
Q3- Find the number and name for suppliers in Amman. Temp1 S-city= ‘Amman’ (Supplier) S-number S-name S-city S100 Ahmed Amman S500 Rana Temp1 Result S-number, S-name (Temp1)
Q3- Find the number and name for suppliers in Amman. Temp1 S-city= ‘Amman’ (Supplier) S-number S-name S-city S100 Ahmed Amman S500 Rana Temp1 Result S-number, S-name (Temp1) S-number S-name S100 Ahmed S500 Rana Result
Q4- For each part shipped, find the part names and the names of all cities storing these parts.
Q4- For each part shipped, find the part names and the names of all cities storing these parts. Temp1 P-number ( Shipment )
Q4- For each part shipped, find the part names and the names of all cities storing these parts. Temp1 P-number ( Shipment ) P-number P1 P2 P3 P4 Temp1
Q4- For each part shipped, find the part names and the names of all cities storing these parts. Temp1 P-number ( Shipment ) Temp2 Part Temp1
Q4- For each part shipped, find the part names and the names of all cities storing these parts. Temp1 P-number ( Shipment ) Temp2 Part Temp1 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 Temp2
Q4- For each part shipped, find the part names and the names of all cities storing these parts. Temp1 P-number ( Shipment ) Temp2 Part Temp1 Result P-name, p-city(Temp2) P-name P-city TV Amman Camera Jarash Video PC Irbid Result
Q5- For each part shipped, find the part numbers and names of all cities supplying the parts.
Q5- For each part shipped, find the part numbers and names of all cities supplying the parts. Temp1 Shipment Supplier
Q5- For each part shipped, find the part numbers and names of all cities supplying the parts. Temp1 Shipment Supplier S-number P-number Quantity S-name S-city S100 P1 100 Ahmed Amman P2 150 P3 200 P4 160 S200 Ali Jarash S300 400 Kasim Irbid S400 Jasim Aqaba 80 S500 Rana Temp1
Result P-number, S-city ( Temp1 ) Q5- For each part shipped, find the part numbers and names of all cities supplying the parts. Temp1 Shipment Supplier P-number S-city P1 Amman P2 P3 P4 Jarash Irbid Aqaba Result P-number, S-city ( Temp1 ) Result
Q6- Get supplier numbers for suppliers who supply part p2
Q6- Get supplier numbers for suppliers who supply part p2 Temp1 p-number = ‘p2’ (Shipment)
Q6- Get supplier numbers for suppliers who supply part p2 Temp1 p-number = ‘p2’ (Shipment) S-number P-number Quantity S100 P2 150 S200 S300 400 S400 Temp1
Q6- Get supplier numbers for suppliers who supply part p2 Temp1 P-number = ‘p2’ (Shipment) Result S-number ( Temp1 ) S-number S100 S200 S300 S400 Result
Relational Algebra Summary: In this learning sequence, we discussed some example queries about purchasing system.
END