DIVISION SQL equivalent relational algebra

Here is an example T(A) = RENTED(A,C) / BOATS(C)

 select distinct R1.A from RENTED R1 where not exists (select * from SAILBOAT S where not exists (select * from RENTED R2 where R1.A = R2.A and R2.C = SC) ); 

My question is: if NOT EXISTS just returns TRUE or FALSE , how does SELECT distinct R1.A know which values ​​to return?

For example, this is jsfiddle

This query returns ALL in the column of numbers if there is a number = 5

+7
sql relational-algebra
source share
1 answer

As wildplasser and sqlvogel mentioned, the subquery will be executed once for each row in the outer query.

The result of the subquery ( TRUE / FALSE ) determines whether the row will be returned in the outer query. Invariably, the columns of the parent key (identifier) ​​of the external query will be referenced in the subquery to check its existence in other tables. This link makes the correlated subquery subquery .

See the updated fiddle .

+1
source share

All Articles