in Databases edited by
500 views
1 vote
1 vote

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?

in Databases edited by
500 views

2 Answers

2 votes
2 votes
Best answer
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 comment

@Prateek Raghuvanshi
can you explain how number of comparisons in first query will be less?

0
0
1 vote
1 vote
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

1 comment

If you could enumerate the difference. Please.
0
0

Related questions