A common table expression, or CTE is a temporary named result set, derived from a simple query. A CTE can later be used within the execution scope of a SELECT, INSERT, UPDATE, or DELETE statement.
An example:
WITH cte_name AS (SELECT name, population, area
FROM country)
They can be chained together as follows:
WITH cte_country_info AS (SELECT *
FROM country
WHERE population > 50000000),
cte_second AS (SELECT name
FROM cte_country_info)
They are very nice to be used to extract away complex parts out of long queries. This helps to make such queries more readable, clean, and maintainable.