learning-it by example

Back to the video

SQL Joins: Inner, Left and Anti, With Real Output

Three queries asked which customers have no orders; NOT IN returned 0 rows because of one NULL.

Video #122 ยท SQL and analytics

Steps in the video

  1. 0:00 Three ways to find customers with no orders. One returned nothing.
  2. 0:34 The idea
  3. 1:05 Setup
  4. 1:24 Data with traps in it
  5. 1:48 Inner and left
  6. 2:03 The loop
  7. 2:51 Three anti joins
  8. 3:54 ON or WHERE
  9. 4:44 What this does not show
  10. 5:09 Mistakes to avoid
  11. 5:35 My take and next steps
  12. 6:05 Recap

Files

  • joins.py (29 lines)
  • run.py (11 lines)
  • shop.py (20 lines)

Download the code (zip)

Tested with

Python 3.12.15

What this does not show

The two tables are tiny and made up, and the join rules are quoted from the PostgreSQL docs and checked only in SQLite.

Sources

Learning IT by Example.