Common Table Expressions (EN)
ConceptTemporary, named result sets within a SQL query
Definition
Common Table Expressions (CTEs) are temporary, named result sets that improve the readability and modularity of complex SQL queries. They are defined with the WITH clause and exist only for the duration of the query. CTEs allow complex queries to be broken down into logical, understandable parts and can contribute to performance optimization through intermediate results.
Architecture
flowchart TD A[WITH-Klausel] --> B[CTE 1] A --> C[CTE 2] A --> D[CTE n] B --> E[SELECT-Anweisung] C --> E D --> E E --> F[Ergebnis]
Im Kontext
- Wird typischerweise zusammen mit Fensterfunktionen und rekursiven Abfragen verwendet
- Verwandt zu: Subqueries, Views, Temp Tables
- Beispiel-Einsatz: Hierarchische Abfragen in Organisationstabellen