edited by
748 views
1 votes
1 votes

If there are three tables to choose from -

Sailors(sid,sname); Reserves(sid,bid); Boats(bid,color)

Question is to choose a sailor who reserved a red boat.

My question is what is the difference between these two TRC expressions.
 

  1. $\{s.sid\,|\,Sailors(s) \wedge (\exists r)(Reserves(r)\, \wedge\, r.sid=s.sid \,\wedge\, (\exists b)(Boats(b)\,\wedge\,r.bid=b.bid\,\wedge\,b.colour=\, 'red' )) \}$
  2. $\{s.sid\,|\,Sailors(s) \wedge (\exists r)(\exists b)(Reserves(r)\,\wedge\, Boats(b)\, \, \wedge\, r.sid=s.sid \wedge\,r.bid=b.bid\,\wedge\,b.colour=\, 'red' ) \}$

Which of the above is correct? Are both correct? Are none correct?

edited by

2 Answers

Best answer
2 votes
2 votes
it is easily understandable when you convert both into relational algebra queries-

(1)$\pi_{sid}[sailor\Join( reserves\Join (\sigma_{color=red}  Boats))] $

(2)$\pi_{sid}[sailor\Join reserves \Join_{color=red}Boats    ]$

as you can see both will give same result "sailors who has reserved red boat" but first one has better format because there will be less no. comparison than second one .
selected by
1 votes
1 votes
1. sid of sailor , who is a sailor and there exist a reserve tuple r such that r.sid = s.sid and there exist a boat b whose boat id is same as sailor reserved and whose color is red. => i think this is true

2. sid of sailor ,  there exist a reserve tuple r and there exist a boat tuple b such that r.sid is same as s.sid and r.bid is same as b.bid and color is red

i think 2nd is also true.

so both are correct

Related questions

0 votes
0 votes
0 answers
3
Tuhin Dutta asked Dec 10, 2017
677 views
What does the following tuple relational calculus query produce?• Student (Student_name, street, city)• Score (Student_name, Branch_name, marks)• Branch (Branch_nam...
0 votes
0 votes
0 answers
4
Tuhin Dutta asked Dec 10, 2017
344 views
Student (Student_name, street, city)• Score (Student_name, Branch_name, marks)• Branch (Branch_name, HOD)• Manages (Student_name, Faculty_name)What does the followi...