Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following queries in relational algebra. 1. Find the name of companies

ID: 3709032 • Letter: W

Question

Write the following queries in relational algebra.
1. Find the name of companies that produce milk
2. Find the cid of companies that produce milk or sugar.
3. Find the cid of companies that produce both milk and sugar.
4. Find the cname of companies that produce same products that are produced by the company name “XYZ”
5. Find the cid of copanies that produce every products.
6. Find the cid of companies that produce milk but not sugar.
7. Find the name of companies that do not produce any product.
8. Find the name of companies that produce at least one product.
9. Find the name of the the most expensive product.
10. Find the pid of the most expensive product that produced by company named “XYZ”

companies (cid:integer, cname:string, address:string) products (pid:integer, pname:string) produce (cid:integer, pid:integer, cost:integer) companies products produce cid cname address 1Torku cid cname 1 milk 2 cola 3 sugar 4teia cid pid cost 1 1 2000 1 3 3000 2 1 1500 2 2 2500 3 2 4000 5 3 3000 5 4 3200 6 13000 6 22500 6 3 3000 6 4 2600 7 2 3000 8 1 2500 8 3 3200 8 4 3000 Konya Ankara 2Sutas 3 NametBursa 4 Tat 61 Pepsi 8Eti Bursa Rize ?stanbul 5 Dogus | Coca cola ?stanbul zmir Windows bu Windows bad iasl Gslac JJa

Explanation / Answer

Select c.cname from companies c innee join produce p on c.cid=p.cid inner join products pd on p.pid=pd.pid where pd.pname='milk';

Select p.cid from produce p inner join products pd on p.pid=pd.pid where pd.pname in ('milk','sugar');

SELECT p.cid from produce p inner join products pd on p.pid=pd.pid where pd.pname ='milk' and pd.pname='sugar';

SELECT c.cname from companies c inner join produce pd on c.cid=pd.cid inner join products p on pd.pid=p.pid where p.pname in (select pd.pname from products pd inner join produce p on p.pid=pd.pid inner join companies c on p.cid=c.cid where c.cname='xyz')

Select pd.cid from produce pd inner join products p on pd.pid =p.pid where p.pname =all(select pname from products);

Select pd.cid from produce pd inner join products p on pd.pid=p.pid where p.pname='milk' and p.pname<>'sugar';

Select cname from companies where Cid not in (select Cid from produce);

Select distinct cname from companies where Cid in (select Cid from produce);

Select pname from products where pid = (select pid from produce where cost = (select max(cost) from produce));

Select p.pid from products p INNER join produce pd on p.pid=pd.pid inner join companies c on pd.cid =c.cid where c.cname ='xyz' and pd.cost=(select max(cost) from produce)