concept
Relational division
Return entities related to every required item. Double NOT EXISTS expresses the absence of an unsatisfied requirement. An empty requirement set admits every candidate under this formulation.
Formal Syntax & Structure
sql syntaxsql
NOT EXISTS (required item for which NOT EXISTS matching relation)Working Example
Example Snippetsql
WITH c(id) AS (VALUES (1),(2)), r(k) AS (VALUES (1),(2)), m(id,k) AS (VALUES (1,1),(1,2),(2,1)) SELECT id FROM c WHERE NOT EXISTS (SELECT 1 FROM r WHERE NOT EXISTS (SELECT 1 FROM m WHERE m.id=c.id AND m.k=r.k)) ORDER BY id;