Saturday, September 8, 2018

Expressing division operator of relational calculus in MYSQL



This is the table r(A,B).

This is the table s(A).
T1<-project(R-S)(R)


T2<-project(R-S)((S x T1)-R)

SQL:
SELECT r.B from r NOT IN
(
  SELECT DISTINCT t1.B from
 (SELECT * from s,(SELECT DISTINCT r2.b from r as r2) as t1)
 except
 (SELECT * from r)
);


T<-T1-T1

SQL:-
(SELECT DISTINCT * from
 s,(SELECT DISTINCT r2.b from r as r2) as t1)
 WHERE * NOT IN
(SELECT * FROM r);



SQL:-

SELECT DISTINCT r.b from r where r.b not IN (SELECT DISTINCT T1.b from (SELECT DISTINCT * from s,(SELECT DISTINCT r2.b from r as r2) as t1) as T1 where not EXISTS(SELECT * from r where T1.a=r.a and T1.b=r.b))