query

Query decorrelation

Decorrelation can replace a dependent query with an equivalent relational operation. Preserve duplicate and NULL semantics; a plain join can multiply outer rows.

Formal Syntax & Structure

sql syntaxsql
WHERE EXISTS (...) / JOIN (SELECT DISTINCT ...)

Working Example

Example Snippetsql
CREATE TABLE a(id int primary key,k int); CREATE TABLE b(k int); INSERT INTO a VALUES (1,10),(2,20),(3,NULL); INSERT INTO b VALUES (10),(10),(NULL);SELECT a.id FROM a JOIN (SELECT DISTINCT k FROM b) AS x ON x.k=a.k ORDER BY a.id;
SQL Reference