GUIDEDeep dive
Subqueries, EXISTS and Window Functions
A subquery can return one value, one column or many rows: = for single values, IN for multiple rows, EXISTS for existence. Window functions rank/accumulate without collapsing rows.
Subqueries
IN (SELECT ...) for multiple rows.
EXISTS (SELECT 1 ...) for existence.
Correlated subqueries reference the outer table.
Window
ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...).
Window functions do not reduce rows.
FAQ
Can a subquery return multiple columns?
Yes, but compare with row values/EXISTS.
What is a CTE?
A named temporary result set declared with WITH.
Sources
Related calculators
Advanced SQL: 1000 Gamified JOIN and Subquery Cards1000 advanced SQL cards covering JOIN, GROUP BY/HAVING, subqueries, EXISTS, CASE and window functions, in 50 levels with spaced repetition.More guides
Hiragana vs KatakanaRead guideSpaced Repetition and the Forgetting CurveRead guideOn Readings vs Kun ReadingsRead guideAn N5 Kanji Study OrderRead guideKEEP READING
Keep reading
Read in order, or jump to another guide on the same topic.
← PreviousSQL JOIN Types and UsageINNER/LEFT JOIN, join conditions and aggregation.Next →Question Tags and ConditionalsPositive/negative tags, three conditional types and tense pairing.