sql - Relational Algebra translation of division -
i came across journal: http://users.dcc.uchile.cl/~cgutierr/cursos/bd/divisionsql.pdf gave method of translating relational algebra division sql. little skeptical if works,
given t1 (a,b) , t2(b)
select t1 b in ( select b t2 ) group having count(*) = ( select count (*) t2 ); because suppose given row in t1[a,b] such there duplicates satisfied statement
where b in (select b t2), wouldn't cause having clause skip row? or "in" statement remove duplicates?
no. relational algebra division takes set of relations (a,b), , returns set of a such there relation between a , members of given subset of bs. example, in paper linked, a1 , a3 as have relation b2 , b3. line where b in ( select b t2 ) filters rows of t1 rows b2 or b3 in b column. equivalent inner join between t1 , t2 on respective bs.
note there no duplicate entries in t1 or t2. few equivalent queries (plus equivalent in journal, though note caveat these queries return empty set if t2 empty, unlike paper's q1):
select t1 exists(select 1 t2 t2.b = t1.b) group having count(*) = ( select count (*) t2 ); select t1 inner join t2 on t1.b = t2.b group having count(*) = ( select count (*) t2 );
Comments
Post a Comment