Site icon Database Tutorials

How To Create a CTE(Common Table Expression)On PostgreSQL

 

With CTE we can generate recursive queries.

We can create a code block and use it over and over again.

In this article, I will illustrate by example how to obtain hierarchical results using CTE.

We create a table using the following script.

 

The following script also adds a few records to the table.

 

With the following script, we create a CTE that creates a hierarchy of all employees.

Exit mobile version