Avijit Roy
Interactive SQL learning resource

SQL JOIN & Analytical Query Explorer

See how joins match rows, how GROUP BY and HAVING summarize data, and how subqueries answer smaller questions. Start with JOIN Explorer, then try grouping and subqueries.

Examples use six fictional clubs and 24 events in public.clubs and public.events. This page simulates results in your browser. For setup instructions, SQL scripts, and further reading, visit the Databases and Data Mining learning repository ↗ and run the SQL in PostgreSQL or Supabase.

First mental model

Which rows must survive?

Keep matched row combinations only

Read the picture as a guide to the rule. Venn regions describe matched and unmatched rows, not counts or one-to-many multiplication. The CROSS grid shows pairs. Check the source and result rows for the actual data.
Actual database consequence

Source rows

CLUBS

club_idclub_name
Source rows

EVENTS

event_idclub_idtitlecategory
Row matching

Step through result rows

Second mental model

Rows → groups → summaries

Think of 24 event cards being sorted into labeled envelopes. The aggregate is calculated inside each envelope.

Before grouping

Rows entering GROUP BY

After HAVING

Groups returned

HAVING removes complete groups, not individual source rows.

GroupCOUNTAVG(capacity)Visual count
Third mental model

A smaller question feeds a larger one

Step 1

Run the inner question mentally

Step 2

Use that answer in the outer question