Skip to main content
Advancedcomparison

CTE vs subquery vs temporary table: when do you use each?

Source: PostgreSQL: SELECT (clause processing)

Quick answerFree

CTEs for readability and recursion; whether they are materialised depends on the engine. Subqueries for simple one-off logic; correlated ones may run per row.

Detailed answer· 49 words

Interview Prep

Unlock the full answer with Interview Prep

Get a 49-word model answer, 4 key points and a visual explainer, plus 247 more SQL questions.

Also in Pro (₹499 / 90 days).

Key points· 4 points

Interview Prep
Unlock with Interview Prep

Visual explainer· animated, step by step

Interview Prep
Unlock with Interview Prep

+ 247 more SQL questions in Interview Prep, each with the full answer.

Discussion