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 = S.C)
);
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 jsfiddle
This query returns EVERYTHING in the numbers column if there exists a number = 5
SELECT ... WHERE TRUE
which naturally should return all rows. If false, then none. – ClaribelclariceNOT EXISTS just returns TRUE or FALSE
it yields one boolean result per row: for every row in the outer query it is decided whether this row is wanted or not. – Serpentiformexist
andnot exist
? Afaik the correct format for the equivalent SQL query to AR division is as follows:SELECT attribute FROM individuals i WHERE NOT EXIST ( SELECT * FROM boats b WHERE NOT EXIST ( SELECT * FROM rented r WHERE r.id = i.id AND r.id = b.id) )
. Posting this in case anyone lands here looking for the answer to that question instead (which would seem more logical in my mind). – Engender