edited by
5,094 views

2 Answers

Best answer
3 votes
3 votes

Relational algebra query for question 1 :

πsname (S3 natural join (R2  natural join σcolor = "Red" V color = "Green"(B1)).

Here first we extract those bid's whose color is red or green then do natural join with R2 to find those sids which have the desired bids found in the earlier step then joining with S3 to get the corresponding names of the extracted sids and finally displaying the names of sailors using projection..

Relational algebra query for question 2 :

For this query to perform we need 2 instances of the table "reserves" so as to find an sid instance which has two different bids..Hence here we need rename operation as well..Then doing natural join with sailors to get the names..Hence the query can be written as : 

πsname(S3 natural join   πsid(R2  conditional join(condition is sid = S ^ bid != B)   ρS,B,D(R2))) 

selected by
1 votes
1 votes
since there are two different tables one for sailors and another one for boat. Both tables are linked via Reserves table. so for the question:: Find the names of sailors who have reserved a red or a green boat.???  

we need to join the table Reserves and Boats and Sailors so the query to get the result should be

SELECT SNAME FROM SAILORS  S , BOATS  B , RESERVES  R   WHERE   R.SID = S.SID AND R.BID = B.BID AND

B.COLOR = ' red ' OR B.COLOR = ' green ' ;

p.s. comment below if you have still any doubt
and for the second question we solve this with the help of group by and subquery

Question.))  Find the names of sailors who have reserved at least two boats?

SELECT SNAME FROM SAILORS WHERE SID IN((SELECT SID FROM RESERVES GROUP BY SID HAVING COUNT(*)>=2));

Related questions

2 votes
2 votes
2 answers
1
Rishi yadav asked Sep 8, 2017
3,116 views
Find SQL :-(Q17) Compute increments for the ratings of persons who have sailed two different boats on the same day.(Q18) Find the ages of sailors whose name begins and en...
1 votes
1 votes
0 answers
2
Prince Sindhiya asked Oct 27, 2018
588 views
SELECT sname FROM s WHERE NOT EXISTS ( SELECT * FROM b WHERE NOT EXISTS ( SELECT * FROM r WHERE r.sid=s.sid AND r.bid=b.bid))how to understand these query please explain
1 votes
1 votes
2 answers
4
aditi19 asked May 8, 2019
1,263 views
Suppliers(sid, sname, address)Parts(pid, pname, color)Catalog(sid, pid, cost)Find the pids of the most expensive parts supplied by suppliers named Yosemite Sham