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”
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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.