A temporary table holds intermediate results that exist only for your session — perfect for breaking a monster analysis into digestible steps without cluttering the database.
Key Points
- Create: CREATE TEMPORARY TABLE tmp_top_customers AS SELECT …;
- Visible only to your session; dropped automatically on disconnect
- Query, index, and join it like any normal table
- Useful when the same intermediate result feeds several queries
- CTEs are cleaner for single-statement logic; temp tables persist across statements
- A temp table can shadow a real table of the same name — name carefully
.png)