First page Back Continue Last page Graphics
Beer example 5
k(S) - k(sL.d = V.d Ù L.b ¹ S.b(L ´ (V S)))
The join (at the end) is clear. We combine it with the drinkers and all the beers they like.
The selection ensures first of all that we have the same drinker, and then there is a strange part: L.b ¹ S.b. Since the cartesian product combines every L tuple with every (V S) tuple the whole tuple is selected if the drinker likes more than one beer or if the bar serves more than one beer. The net result here is that this subquery (including k) selects all the bars except those that serve only one beer and only have visitors that only like that (same) one beer.
We finally take the complement, so we list all bars that serve only one beer, and that only have visitors who like only that one (served) beer (and nothing else).
Notes:
Deze query is van Tim van der Avoort (foute query voor bier vraag n).