The Gateway to Computer Science Excellence
+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\,\,\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\,\,\wedge\,b.colour=\, 'red' ) \}$

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

in Databases by (261 points)
edited by | 183 views

2 Answers

+1 vote
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 .
by Boss (10.8k points)
selected by

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

+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 is same as and color is red

i think 2nd is also true.

so both are correct
by Active (3.3k points)
If you could enumerate the difference. Please.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,741 questions
57,242 answers
104,603 users