Welcome to our Recursive Queries in PostgreSQL course, where we'll show you how to use recursive queries and Common Table Expressions to make building complex queries easier.
Common Table Expressions (CTEs), often simply called WITH
clauses, are essentially just named subqueries. They are a fairly new feature of SQL; with CTEs, you can break a long query into smaller chunks, which makes it more readable. Unlike SQL subqueries, CTEs can be recursive, allowing the traversal of hierarchical models of enormous depth.
WITH
clauses have been available in PostgreSQL since version 8.4. This course covers simple CTEs, nested CTEs, and recursive CTEs. You will learn how to manage your SQL queries with CTEs, how and when to nest CTEs, and how to use recursive CTEs to move through hierarchical data models.
In the first part of the course, you will test your knowledge about basic SQL. You need fundamental SQL knowledge to complete this course, which covers some advanced material.
We assume that you know how to filter rows in a table, sort data, and use aggregate functions with GROUP BY
and HAVING
. You will also need to be able to join tables and use subqueries and set operators.
Check your knowledge: Start with our short quiz to test your SQL skills!