These are the list of 3 tables
EMPLOYEE (Ssn#, Fname, Lname, Bdate, Address, Sex, Salary, Super_ssn)
WORKS_ON (Essn#, Pno, Hours)
PROJECT (Pnumber#, Pname, Plocation)
Question 1: Write SQL query (equivalent to relational division of relational algebra) to retrieve the project name which is contributed by all employees
Question 2: Write SQL query (equivalent to relational division of relational algebra) to retrieve the first name and last name of all employees who work on every project
Then there are list of 6 tables
ITEM (Item#, Item_Name, Unit_Price)
ORDER (Order#, Ord_Date, Cust#, Ord_Amt)
ORDER_ITEM (Order#, Item#, Qty)
WAREHOUSE (Warehouse#, Warehouse_City)
SHIPMENT (Order#, Warehouse#, Ship_Date)
WAREHOUSE_ITEM (Item#, Warehouse#, Qty)
Question 3: Write SQL query (equivalent to relational division of relational algebra) to list Item_Name and Quantity that are stored in all warehouses in Sydney
All these 3 questions are assignment questions.
However, I have tried and answered them and which is shown below:
Answer for Question 1:
SELECT Pname
FROM PROJECT
WHERE EXISTS (SELECT Pname
FROM PROJECT, EMPLOYEE
WHERE PROJECT.Pnumber = WORKS_ON.Pno);
Answer for Question 2:
SELECT Fname, Lname
FROM EMPLOYEE
WHERE EXISTS (SELECT Fname, Lname
FROM EMPLOYEE, WORKS_ON, PROJECT
WHERE EMPLOYEE.Ssn = WORKS_ON.Essn
AND WORKS_ON.Pno = PROJECT.Pnumber);
Answer for Question 3:
SELECT Item_Name, Qty
FROM ITEM, ORDER_ITEM
WHERE ITEM.Item# = ORDER_ITEM.Item#
AND EXISTS(SELECT *
FROM WAREHOUSE
WHERE Warehouse_City = 'Sydney');
I just want to confirm that if my SQL query logic for these 3 questions are correct or not.
If it is correct, then I will able to proceed and convert them in relational algebra with relational division which I can do it by myself if my SQL query logic is correct.
If it is not correct, then kindly correct the mistakes in my SQL query logic wherever applicable which would be very helpful for me.
Best Answer
Here is a short and concise article describing the various techniques for relational division in SQL, with an example similar to yours using students and courses instead of employees and projects: http://www.inf.usi.ch/faculty/soule/teaching/2016-fall/db/division.pdf