Common Table Expression Basics


Introduction

Firstly, we need to understand what is a common table expression. Common table expressions, also abbreviated as CTE, are virtual tables which are formed by collecting and formatting data from one or multiple source table(s). These virtual tables are not created permanently, which means they are only available during the query execution. Once the query execution is complete, the tables are automatically removed.

Let us look into the proper way of writing a CTE first:

WITH our_cte AS ( SELECT col1, col2, col3 FROM TABLE ) SELECT col1, col3 FROM our_cte WHERE ….

The name of our CTE is