Making relational algebra equations in a sample database

214 views Asked by At

I came across a practice paper on relational algebra of Stanford University with relations as:-

Person ( name, age, gender ) name is a key.

Frequents ( name, pizzeria ) (name, pizzeria) is a key.

Eats ( name, pizza ) (name, pizza) is a key.

Serves ( pizzeria, pizza, price ) (pizzeria, pizza) is a key.

These two were the questions I couldn't get. 1.Find the names of all people who frequent only pizzerias serving at least one pizza they eat.

2.Find the names of all people who frequent every pizzeria serving at least one pizza they eat.

Firstly I couldn't get the difference between the meaning of the two questions. Secondly, can anyone explain me the answer to these questions as given in the website? The link to the webpage is given below. The questions correspond to the parts g., and h., of the first question.

http://openclassroom.stanford.edu/MainFolder/courses/IntroToDatabases/old-site/docs/backup/ra-exercises.html

1

There are 1 answers

0
Erwin Smout On BEST ANSWER

The difference between the two :

"Find the names of all people who frequent every pizzeria serving at least one pizza they eat." has "every pizzeria serving ..." as qualifying condition. Let's say the set of these pizzeria's is {P1 P2}. Let's say the set of pizzeria's I frequent is {P1 P2 P3}. Even with P3 included in that set, it is still the case that I frequent "... every pizzeria serving ...", because there does not exist any pizzeria Px that serves at least one pizza I eat (Px is thus either P1 or P2) and that I do not frequent. You might wonder why I would frequent P3 if it doesn't serve anything I eat, well that might e.g. be so I can figure out whether they have started serving something I eat. Brief : the qualifying condition is whether {P1 P2} is a subset of the pizzeria's I frequent.

"Find the names of all people who frequent ONLY pizzerias serving at least one pizza they eat." has a different qualifying condition. In this case, my frequenting P3 disqualifies me for the result set. Note carefully that I do not have to frequent ALL of {P1 P2}. If I frequent only P1, or even no pizzeria at all (!!!!!!!! a dangerous edge case that is very often wrongly overlooked), it is still the case that I only frequent pizzeria's serving at least one pizza I eat. Brief : the qualifying condition is whether the pizzeria's I frequent is a subset of {P1 P2}.

Yet another qualifying condition would be "frequent all and only those pizzeria's ...". In that case, the qualifying condition is equality between the two sets mentioned.