In this section we will explore the intricacies of converting fairly complex first-order logic statements into relational queries.
We assume the existence of three attributes: bars, beers, and drinkers and three relations:
SERVES(b, e), where b=bar, e=beer
LIKES(d, e), where d= drinker, e=beer
FREQUENTS(d, b), where d=drinker, b=bar.Since we will encounter many unsafe formulas in the following sections, we also define:
SELECT INTO DRINKERUNIVERSE
d
FROM LIKES
UNION
(SELECT d
FROM FREQUENTS);and
SELECT INTO BARUNIVERSE
e
FROM SERVES
UNION
(SELECT b
FROM FREQUENTS);and
SELECT INTO BEERUNIVERSE
e
FROM LIKES
UNION
(SELECT e
FROM SERVES);