mysqlsqltuplestuple-relational-calculus

How to implement sql "where not in" in tuple relational calculus?


I want to convert a sql query which has where not in clause to tuple relational calculus.Existential and Universal quantifier implements only where exists and where not exists clause so I want to know how to implement where not in?

My tables are serves(bar,beer),frequents(drinker,bar),likes(drinker,beer).The following query selects the drinkers that frequent only bars that serve some beer they like.

select distinct f2.drinker from frequents f2 where f2.drinker not in (select f1.drinker from frequents f1 where (f1.bar,f1.drinker) not in (select f.bar,f.drinker from frequents f,serves s,likes l where l.beer=s.beer and f.bar=s.bar and f.drinker=l.drinker))

It's enough if someone can explain me how to implement where not in in TRC no need to convert the entire query.I am using http://www-rohan.sdsu.edu/~eckberg/relationalcalculusemulator.html
to check my relational calculus and convert it into sql query.

Note:

If you use implications in your query.

It does not support implication.For example implication can be implemented as follows.(p==>q) can be written as (not p or q) form as both are logically equivalent.


Solution

  • I rewrote my query with where exists and where not exists and now its easy to convert it into relational calculus.The answer is

    {T.drinker|∃f2Єfrequents (∀f1Єfrequents (∃fЄfrequents(∃sЄserves ∃lЄlikes(s.beer=l.beer^l.drinker=f.drinker^s.bar=f.bar^f1.drinker=f.drinker^f.bar=f1.bar^f2.bar=f1.bar v f2.drinker≠f1.drinker)))}

    Anyways thanks for the inputs.