As a relation
As a scalar
NULL; more than one row is an error.
IN and EXISTS
EXISTS to test whether a matching row exists and IN to test membership
in a set of values. The optimizer may rewrite either into a join; inspect
EXPLAIN before choosing one for performance reasons.
NOT IN and NOT EXISTS differ on nulls: NOT IN against a set containing a
null yields no rows, because the comparison is unknown rather than false. Prefer
NOT EXISTS unless you have ruled nulls out.
Correlated subqueries
A subquery referencing a column from the enclosing query, such asd.id above,
is correlated, and is conceptually evaluated per outer row. The planner usually
rewrites it into a join.