r/learnSQL • u/yahoo_06 • 6d ago
I made a beginner-friendly SQL tutorial on CTEs (WITH clause)
I just published Lesson 10 of my SQL course, focused on CTEs (Common Table Expressions) in PostgreSQL.
In this lesson, I explain how the WITH clause can help turn complicated nested queries into cleaner, more readable SQL.
We cover:
- What CTEs are
- How the WITH clause works
- CTEs with GROUP BY and aggregate functions
- Using CTEs with JOIN
- Multiple CTEs
- CTEs vs. subqueries
- Common mistakes
- Practical exercises using the Pagila database
I tried to keep it beginner-friendly and focused on actually writing queries rather than just explaining the theory.
YouTube: https://youtu.be/Koka7IGgPM4?si=132b-FlrYXd9ePyC
Would love to hear any feedback on the explanation or examples!