Advanced Queries and Joins
Table of Contents
Introduction: The Query That Made Me Realise I Knew Nothing
Recap: JOIN Types Refresher
Advanced JOIN Techniques
Self JOIN
Multiple JOINs in One Query
LATERAL JOIN
Subqueries: Queries Within Queries
Scalar Subquery
IN and EXISTS Subqueries
Derived Tables (Subquery in FROM)
Common Table Expressions (CTEs)
Basic CTE
Chained CTEs
Recursive CTEs
Window Functions
RANK and ROW_NUMBER
Running Totals and Moving Averages
LAG and LEAD
FIRST_VALUE and LAST_VALUE
UNION, INTERSECT, and EXCEPT
Advanced Filtering and Aggregation
FILTER Clause
GROUPING SETS, ROLLUP, CUBE
Full-Text Search in PostgreSQL
Query Patterns for the Blog System
Pattern 1: Dashboard Overview
Pattern 2: Author Leaderboard
Pattern 3: Related Posts
Common Mistakes and How to Avoid Them
1. N+1 Query Problem
2. Forgetting NULL Handling
3. HAVING vs WHERE Confusion
4. Implicit vs Explicit JOINs
Performance Implications
Technique
Performance Notes
What I Learned About Advanced Queries
Next Steps
Last updated