Module 2 › Session 19 · FULL OUTER JOIN & Data Reconciliation

FULL OUTER JOIN & Data Reconciliation

Reconcile distributed financial ledgers, audit department headcounts, and eliminate two-sided relational blindspots with FULL OUTER JOIN and COALESCE key unification.

Jo class mein bola, yahan nukte mein likha hai.
What I said in class, written here as key points.

← All NukteSELECT * FROM TheShiraverse
MODULE 02 • SESSION 19 • TOPIC 23

FULL OUTER JOIN & Data Reconciliation

Two-Sided Relational Audits • The COALESCE Key Law • Symmetric Difference
23
Interactive Scenes
1
Practice Arena
4
Worked Drills
8
Interview Scenarios
Core Focus: Two-Sided Preservation • The COALESCE Law • Financial Reconciliation • Outer Demotion Traps
✓ Ready For Live Execution

Today’s Agenda — Two-Sided Reconciliation

A four-phase operational blueprint for ledger reconciliation, symmetric difference, and bidirectional integrity audits.

Pillar 01
◆ Two-Sided Outer Joins
01 The Complete Relational Union
02 Preserving Left & Right Gaps
03 Bidirectional NULL Value Padding
Pillar 02
⚠ The Non-Negotiable COALESCE Law
04 The Raw Key NULL Catastrophe
05 COALESCE Key Unification Bridge
06 Multi-Entity Grain Reconciliation
Pillar 03
💰 Financial Ledger Audits
07 Orders vs Payment Gateway
08 Symmetric Difference Queries
09 Unbilled & Unpaid Variances
Pillar 04
⚒ Engine & Mastery
10 Hash Full Outer Join Execution
11 4-Level Practice Arena Drills
12 8 Senior Technical Interview Traps
💡
Why this matters: INNER JOIN finds agreements; LEFT JOIN finds unilateral records; Anti-Join finds single-sided absence. But enterprise financial and analytics systems require bidirectional audits: reconciling ledger settlements against gateway records, discovering orphan payments, and surfacing discrepancies where either side could be missing. FULL OUTER JOIN is the cornerstone of reconciliation architecture.

Where We Left Off: Single-Sided Absence to Bidirectional Auditing

Transitioning from one-way absence detection to comprehensive two-sided reconciliation

🔍 SESSION 18 • COMPLETED

Single-Sided Absence

-- Session 18: Anti-Join formula
SELECT
c.customer_id, c.first_name,
c.email, c.registration_date
FROM customers.customers c
LEFT JOIN sales.orders o
ON c.customer_id = o.cust_id
WHERE o.order_id IS NULL
LIMIT 5;
-- Detects left rows with zero right matches
Session 18 mastered single-sided absence: finding customers who never ordered, or products never sold. But LEFT JOIN only preserves the left table. What if transactions exist in the payment gateway that have no matching order in the database?
✓ Single-sided absence mastered; two-sided reconciliation awaits
◆ SESSION 19 • THE MISSION

Two-Sided Reconciliation

-- Session 19: Full outer reconciliation
SELECT
COALESCE(o.order_id, p.order_id) AS audit_id,
o.net_total AS order_amount,
p.amount AS paid_amount,
CASE WHEN o.order_id IS NULL THEN 'Orphan'
WHEN p.payment_id IS NULL THEN 'Unpaid'
ELSE 'Matched' END AS status
FROM sales.orders o
FULL OUTER JOIN sales.payments p
ON o.order_id = p.order_id;
Master bidirectional reconciliation. Preserve unmatched rows from BOTH sides simultaneously and unify keys using the mandatory COALESCE pattern.
◆ Today: FULL OUTER JOIN, COALESCE Law, Ledger Variances
💡
The Core Rule: FULL OUTER JOIN emits three distinct groups: (1) matched rows where both keys exist, (2) left rows with right-side NULLs, and (3) right rows with left-side NULLs. NEVER select a raw primary key (o.order_id) without COALESCE — doing so turns valid right-only rows into nameless NULLs.
💰
The ₹48 Lakh Settlement Ledger Discrepancy FINANCIAL AUDIT • PAYMENT GATEWAY RECONCILIATION
EXAMPLE STORY • NAMES & NUMBERS MADE UP
₹48 Lakh Ledger Discrepancy
2-Sided Relational Blindspot
1 Pass FULL OUTER + COALESCE
STEP 01 • THE INCIDENT
chief-financial-officer 08:45 AM
“Finance audit failed! Internal ERP shows ₹4.2 crore in completed orders, but payment gateways settled ₹3.72 crore. We have a ₹48 lakh discrepancy. An INNER JOIN hid missing payments, and a LEFT JOIN hid orphan deposits. We need a complete two-sided audit immediately!”
Single-sided joins created blind spots: unilateral preservation discarded records from the opposite ledger.
STEP 02 • ROOT CAUSES
⚠ Unilateral Blindspot
LEFT JOIN Drops Gateway Data
LEFT JOIN only preserves orders, silently deleting gateway settlements that had no matching order ID.
⚡ Raw Key NULL Trap
Nameless Discrepancy Rows
Selecting raw o.order_id in a FULL OUTER JOIN emitted NULL for orphan gateway payments, wiping audit IDs.
🔗 Silent Discrepancy
INNER JOIN Hides the Gap
Analyst used INNER JOIN which only showed orders where payments already matched, blinding finance to the gap.
STEP 03 • THE FULL OUTER SOLUTION
FULL OUTER + COALESCE
💰 Ledger Reconciliation Query
SELECT
  COALESCE(o.order_id, p.order_id) AS id,
  ROUND(COALESCE(o.net_total, 0), 2) AS bill,
  ROUND(COALESCE(p.amount, 0), 2) AS paid,
  ROUND(COALESCE(p.amount, 0) -
        COALESCE(o.net_total, 0), 2) AS diff,
  CASE
    WHEN o.order_id IS NULL THEN 'Orphan'
    WHEN p.payment_id IS NULL THEN 'Unpaid'
    ELSE 'Discrepancy'
  END AS status
FROM sales.orders o
FULL OUTER JOIN sales.payments p
  ON o.order_id = p.order_id
WHERE COALESCE(o.net_total, 0) !=
      COALESCE(p.amount, 0)
ORDER BY 4 DESC LIMIT 10;
-- Full 2-sided audit with COALESCE
✓ Full Ledger Tie-Out 2-Sided Discrepancy Audit
STEP 04 • CORE PRINCIPLE
The Moral: In financial auditing, never assume data exists on both sides. Always use FULL OUTER JOIN with the non-negotiable COALESCE key pattern to surface unbilled receipts and unpaid invoices in a single query!

From Story → SQL: The Algebra of Reconciliation

How relational algebra constructs a complete bidirectional envelope across disjoint systems.

COMPLETE ENVELOPE
The Total Set Union
In set theory, FULL OUTER JOIN computes (A ∩ B) ∪ (A − B) ∪ (B − A). Every record from both tables survives.
BIDIRECTIONAL NULLS
Universal Padding
When Table A has no match in B, B's columns are NULL. When Table B has no match in A, A's columns are NULL. Neither side is dropped.
CLASSIFICATION MATRIX
CASE Expression Triangulation
By evaluating IS NULL on both primary keys, SQL classifies each row into Reconciled, Unpaid, or Orphan Gateway Payment.
• THE GOLDEN KEY LAW: In a FULL OUTER JOIN, selecting a single table's ID column leaves gaps. You MUST wrap keys in COALESCE(a.id, b.id) to guarantee a persistent identifier!

Visual Studio: The FULL OUTER JOIN Relational Matrix

Click join perspectives below to visualize the bidirectional envelope and record preservation.

RELATIONAL PERSPECTIVE:
INTERSECTION • MATCHED RECONCILED TRANSACTION
Order #1001 (₹4,500) ↔ Payment #P01 (₹4,500) → RECONCILED
Both Sides Present: Order exists and payment was captured. Billed and received amounts match exactly.
Pillar 01
Matched Intersection
Rows that exist in both tables with equal join keys. Both left and right attributes are populated.
Pillar 02
Left-Only Discrepancy
Rows existing only in Table A. Right-side columns are padded with NULLs (e.g. unpaid orders).
Pillar 03
Right-Only Discrepancy
Rows existing only in Table B. Left-side columns are padded with NULLs (e.g. orphan payments).

FULL OUTER JOIN: Syntax & Bidirectional Preservation

Constructing complete relational envelopes across financial ledgers in PostgreSQL 18.

Pillar 01
Bidirectional Scope
Writing FROM table_a FULL OUTER JOIN table_b ON a.id = b.a_id guarantees neither table suffers row loss.
Pillar 02
Universal NULL Padding
Unmatched rows from either table are preserved with NULL values for the missing partner's columns.
Pillar 03
Classification with CASE
Combine IS NOT NULL checks to classify each output row into business reconciliation categories.
POSTGRESQL 18 • ORDERS VS PAYMENTS RECONCILIATION
SELECT
  COALESCE(o.order_id, p.order_id) AS reconciled_order_id,
  o.net_total AS order_amount,
  p.amount AS paid_amount,
  CASE
    WHEN o.order_id IS NOT NULL AND p.payment_id IS NOT NULL THEN 'Fully Reconciled'
    WHEN o.order_id IS NOT NULL AND p.payment_id IS NULL THEN 'Pending Payment'
    ELSE 'Orphan Gateway Payment'
  END AS reconciliation_status
FROM sales.orders o
FULL OUTER JOIN sales.payments p
  ON o.order_id = p.order_id
ORDER BY reconciled_order_id DESC
LIMIT 15;

Visual Studio: The Non-Negotiable COALESCE Key Law

Click below to observe why selecting a single join key produces dangerous NULL identifiers.

KEY RESCUE:
SCENARIO 1: LEFT-ONLY ROW (UNPAID ORDER #101)
o.order_id = 101 | p.order_id = NULL → COALESCE(o.order_id, p.order_id) = 101
Left Key Preserved: Because the payment is absent, p.order_id is NULL. COALESCE falls back to o.order_id (101).
Trap 01
The Phantom NULL ID
Selecting SELECT o.order_id yields NULL for all right-only orphan records!
Rescue 02
COALESCE Unification
COALESCE(o.order_id, p.order_id) returns whichever ID is non-NULL.
Standard 03
100% Populated Key
Guarantees that downstream reports, BI dashboards, and exports have an unbroken identifier.

The Non-Negotiable COALESCE Law: Key Unification

Why selecting raw table keys in FULL OUTER JOIN causes data corruption and how COALESCE fixes it.

Pillar 01
The Single-Key Fallacy
If a row exists only in Table B, Table A.id evaluates to NULL. Downstream grouping and dashboards fail immediately.
Pillar 02
The Unification Law
Always define COALESCE(left.pk, right.foreign_key) AS unified_id. It evaluates arguments in order, returning the first non-null value.
Pillar 03
Grouping Reliability
When aggregating outer-joined tables, group by the unified COALESCE expression to prevent splitting records across NULL buckets.
POSTGRESQL 18 • COALESCE KEY UNIFICATION DEMO
SELECT
  o.order_id AS raw_order_id,
  s.order_id AS raw_shipment_order_id,
  COALESCE(o.order_id, s.order_id) AS unified_order_id,
  o.order_status,
  s.courier_name,
  s.shipped_date
FROM sales.orders o
FULL OUTER JOIN sales.shipments s
  ON o.order_id = s.order_id
WHERE o.order_id >= 149990
ORDER BY unified_order_id DESC
LIMIT 15;

Visual Studio: Financial Reconciliation Matrix

Click transaction classifications below to observe ledger balance calculations and variance detection.

LEDGER STATUS:
CLASSIFICATION: FULLY RECONCILED (BALANCED)
Billed: ₹5,000 • Received: ₹5,000 • Discrepancy: ₹0 (Clean Match)
Perfect Alignment: Both records exist, and billed net total matches received gateway settlement to the exact paisa.
Status 01
Fully Reconciled
Billed order amount equals received payment gateway amount (Discrepancy = ₹0).
Status 02
Variance Discrepancy
Partial payments or overpayments: received_amount != billed_amount.
Status 03
One-Sided Orphans
Completely unpaid orders (7,550 in RetailMart) or unlinked gateway settlement records.

Ledger Variance Audit: Detecting Financial Discrepancies

Calculating exact rupee variances across mismatched transactions and unpaid invoices in RetailMart.

Pillar 01
COALESCE Arithmetic
Because missing records return NULL, arithmetic like p.amount - o.net_total yields NULL! Wrap amounts in COALESCE(col, 0) before subtracting.
Pillar 02
Variance Directionality
A negative variance indicates underpayment or revenue loss. A positive variance indicates unlinked customer credits or overpayment.
Pillar 03
The Discrepancy Filter
Filter WHERE COALESCE(o.net_total, 0) != COALESCE(p.amount, 0) to eliminate clean matches and isolate balance errors.
POSTGRESQL 18 • MULTI-LAKH LEDGER VARIANCE AUDIT
SELECT
  COALESCE(o.order_id, p.order_id) AS order_id,
  ROUND(COALESCE(o.net_total, 0), 2) AS billed_rupees,
  ROUND(COALESCE(p.amount, 0), 2) AS received_rupees,
  ROUND(COALESCE(p.amount, 0) - COALESCE(o.net_total, 0), 2) AS variance_rupees,
  CASE
    WHEN o.order_id IS NULL THEN 'Orphan Gateway Payment'
    WHEN p.payment_id IS NULL THEN 'Completely Unpaid'
    WHEN p.amount < o.net_total THEN 'Underpaid Order'
    WHEN p.amount > o.net_total THEN 'Overpaid Order'
    ELSE 'Exact Match'
  END AS reconciliation_status
FROM sales.orders o
FULL OUTER JOIN sales.payments p
  ON o.order_id = p.order_id
WHERE COALESCE(o.net_total, 0) != COALESCE(p.amount, 0)
ORDER BY ABS(COALESCE(p.amount, 0) - COALESCE(o.net_total, 0)) DESC, order_id DESC
LIMIT 15;

Visual Studio: Organizational Hierarchy & Ghost Records

Click below to trace department vacancies, unallocated personnel, and rogue headcount records.

ROSTER AUDIT:
ORGANIZATION: ACTIVE STAFFED DEPARTMENT
Dept #10 (Customer Care) ↔ 42 Employees Assigned → OPERATIONAL
Normal State: Department exists in master dimension, and staff members are assigned with valid foreign keys.
Case 01
Operational Unit
Department exists in master dimension with active personnel allocated.
Case 02
Vacant Department
Department chartered in company records, but headcount is currently 0.
Case 03
Broken Foreign Key
Employee assigned to non-existent department code; caught by outer join.

Symmetric Difference: Isolating Pure Discrepancies

Filtering for rows that exist in either System A or System B, but never in both simultaneously.

Pillar 01
The Symmetric Formula
In set theory, symmetric difference is (A Δ B) = (A − B) ∪ (B − A). It excises matching records to show only pure gaps.
Pillar 02
The IS NULL OR IS NULL Scalpel
To isolate discrepancies in SQL, filter WHERE table_a.pk IS NULL OR table_b.pk IS NULL. All matched rows vanish immediately.
Pillar 03
Pipeline Exception Reporting
Automated data quality pipelines run symmetric difference queries hourly to alert engineering to webhook or sync failures.
POSTGRESQL 18 • SYMMETRIC DIFFERENCE ON ORDERS & SHIPMENTS
SELECT
  COALESCE(o.order_id, s.order_id) AS audit_order_id,
  o.order_status,
  s.courier_name,
  s.status AS shipment_status,
  CASE
    WHEN o.order_id IS NOT NULL AND s.shipment_id IS NOT NULL THEN 'Fulfilled & Shipped'
    WHEN o.order_id IS NOT NULL AND s.shipment_id IS NULL THEN 'Unshipped / Cancelled'
    ELSE 'Orphan Courier Tracking'
  END AS fulfillment_audit
FROM sales.orders o
FULL OUTER JOIN sales.shipments s
  ON o.order_id = s.order_id
WHERE o.order_id IS NULL OR s.shipment_id IS NULL
ORDER BY audit_order_id DESC
LIMIT 15;

Common Mistakes: FULL OUTER JOIN Hazards

Avoid these four classic traps when conducting two-sided reconciliation audits.

MISTAKE 01
Selecting a Single Join Key
Writing SELECT o.order_id emits NULL for all right-only orphan records! Always write COALESCE(o.order_id, p.order_id) to guarantee identity.
MISTAKE 02
WHERE Clause Outer Demotion
Writing WHERE p.amount > 1000 destroys the FULL OUTER JOIN! Right-only or left-only NULL amounts fail the filter, silently demoting to a RIGHT JOIN.
MISTAKE 03
Unwrapped NULL Arithmetic
Computing p.amount - o.net_total yields NULL whenever an order is unpaid or orphan! Always wrap numbers: COALESCE(p.amount, 0) - COALESCE(o.net_total, 0).
MISTAKE 04
Missing Discrepancy OR Guard
Symmetric difference requires WHERE a.id IS NULL OR b.id IS NULL. Writing AND returns zero rows because no row can be missing on both sides!
▶ Enter Practice Arena

Practice Arena — FULL OUTER JOIN Masterclass

Write and execute two-sided reconciliation audits in PostgreSQL 18 across 4 difficulty tiers.

Interview Masterclass: FULL OUTER JOIN & Reconciliation

Authentic technical interview questions asked by senior engineering panels at top tech firms.

01 FULL OUTER JOIN Purpose
02 The COALESCE Join Key Law
03 WHERE Clause Outer Demotion
04 Symmetric Difference
05 Variance Calculations
06 Aggregations with FULL JOIN
07 Multiplicity in Outer Joins
08 Anti-Join vs FULL OUTER JOIN
RELATIONAL CONCEPTS
“What is a FULL OUTER JOIN, and in what business problems is it irreplaceable?”
A FULL OUTER JOIN combines the results of both LEFT and RIGHT outer joins. It preserves all rows from both tables, matching where possible, and padding with NULLs on either side when unmatched.

Essential Use Cases:
1. Financial reconciliation (Order totals vs Bank statement credits).
2. Logistics reconciliation (Warehouse dispatches vs Courier deliveries).
3. Catalog audits (Products in catalog vs Products in transaction ledger).
Interview Trap: Using INNER JOIN or LEFT JOIN for auditing. INNER JOIN hides discrepancies on both sides; LEFT JOIN only shows your own perspective.

Self-Check: Interactive Memory Flashcards

Click each card to reveal the underlying architectural answer and test your retention.

What does FULL OUTER JOIN return?
Click to reveal architectural answer ›
All rows from BOTH tables: matched rows + left-only rows with NULL right columns + right-only rows with NULL left columns.
Why must you select COALESCE(a.id, b.id) in a FULL OUTER JOIN?
Click to reveal architectural answer ›
Because if a row exists only in Table B, a.id is NULL! COALESCE guarantees a populated identifier on every row.
How does adding WHERE b.amount > 1000 affect a FULL OUTER JOIN?
Click to reveal architectural answer ›
It silently demotes the FULL OUTER JOIN into a RIGHT JOIN because rows where Table B is missing have NULL amounts, which fail the filter!
How do you isolate the Symmetric Difference between two systems?
Click to reveal architectural answer ›
Perform a FULL OUTER JOIN and filter WHERE a.id IS NULL OR b.id IS NULL to find records in System A or B, but not both.
Why does simple subtraction (payment - order_amount) fail?
Click to reveal architectural answer ›
Because NULL minus a number evaluates to NULL! You must wrap amounts in COALESCE(col, 0) before subtracting.
When grouping on a FULL OUTER JOIN, what column must you group by?
Click to reveal architectural answer ›
Always group by the COALESCE expression: GROUP BY COALESCE(a.dept_id, b.dept_id) to avoid collapsing orphans into a NULL bucket.
How many orders in RetailMart have zero recorded payments?
Click to reveal architectural answer ›
Exactly 7,550 orders in sales.orders have zero recorded payments in sales.payments.
How does FULL OUTER JOIN scale in PostgreSQL 18?
Click to reveal architectural answer ›
PostgreSQL uses Hash Full Join or Merge Full Join algorithms, maintaining linear O(N + M) performance on indexed keys.

Key Takeaways: 4 Pillars of Bidirectional Reconciliation

The four core architectural laws governing two-sided relational audits.

PILLAR 01
Two-Sided Envelope
FULL OUTER JOIN preserves 100% of rows from both tables, exposing matches, left-only gaps, and right-only orphans in one unified pass.
PILLAR 02
The COALESCE Law
Never select a raw table key. Always wrap keys in COALESCE(left.pk, right.foreign_key) to guarantee every audit record displays an identifier.
PILLAR 03
Outer Demotion Guard
Conditions on preserved tables must stay in the ON clause. Placing right-table criteria in WHERE demotes the query into a RIGHT JOIN.
PILLAR 04
Symmetric Difference
Filter WHERE a.id IS NULL OR b.id IS NULL to discard matched records and extract pure discrepancies for automated compliance alerts.

Quick Reference: FULL OUTER JOIN Syntax Blueprint

Production SQL templates for two-sided reconciliation, COALESCE keys, and discrepancy audits.

Core Reconciliation Patterns
Basic Reconciliation & COALESCE Key:
COALESCE JOIN KEY
▶ Run
SELECT
  COALESCE(o.order_id, p.order_id) AS reconciled_id,
  o.net_total, p.amount
FROM sales.orders o
FULL OUTER JOIN sales.payments p ON o.order_id = p.order_id
ORDER BY reconciled_id DESC LIMIT 10;
Status Classification Matrix:
STATUS CLASSIFICATION
▶ Run
SELECT
  COALESCE(o.order_id, p.order_id) AS order_id,
  CASE
    WHEN o.order_id IS NOT NULL AND p.payment_id IS NOT NULL THEN 'Reconciled'
    WHEN o.order_id IS NOT NULL THEN 'Unpaid'
    ELSE 'Orphan Payment'
  END AS status
FROM sales.orders o
FULL OUTER JOIN sales.payments p ON o.order_id = p.order_id
ORDER BY order_id DESC LIMIT 10;
Audits & Variances
Symmetric Difference (Discrepancy Gaps):
SYMMETRIC DIFFERENCE
▶ Run
SELECT
  COALESCE(o.order_id, s.order_id) AS audit_order_id,
  o.order_status, s.courier_name
FROM sales.orders o
FULL OUTER JOIN sales.shipments s ON o.order_id = s.order_id
WHERE o.order_id IS NULL OR s.shipment_id IS NULL
ORDER BY audit_order_id DESC LIMIT 10;
Rupee Amount Variance Calculation:
AMOUNT VARIANCE AUDIT
▶ Run
SELECT
  COALESCE(o.order_id, p.order_id) AS order_id,
  ROUND(COALESCE(p.amount, 0) - COALESCE(o.net_total, 0), 2) AS variance
FROM sales.orders o
FULL OUTER JOIN sales.payments p ON o.order_id = p.order_id
WHERE COALESCE(o.net_total, 0) != COALESCE(p.amount, 0)
ORDER BY ABS(COALESCE(p.amount, 0) - COALESCE(o.net_total, 0)) DESC, order_id DESC LIMIT 10;

Take-Home Challenge: Two-Sided Enterprise Audits

Three enterprise reconciliation challenges to test your mastery of FULL OUTER JOIN.

TASK 01
The Unsettled Ledger Audit
Perform a FULL OUTER JOIN between sales.orders and sales.payments. Filter for unpaid orders where payment is missing. Calculate total unpaid rupee revenue.
Verification: RetailMart holds exactly 7,550 unpaid orders. Order by order_id DESC LIMIT 20.
TASK 02
Fulfillment Pipeline Exception Report
Reconcile sales.orders against sales.shipments with symmetric difference: WHERE o.order_id IS NULL OR s.shipment_id IS NULL.
Verification: Exactly 45,013 unshipped or canceled orders surface for logistics follow-up.
TASK 03
Department Headcount Matrix
Connect core.dim_department and stores.employees with FULL OUTER JOIN. Group by unified department key and report total staff count and average salary.
Verification: All 10 corporate departments are accounted for. Order by total_headcount DESC, dept_key ASC.

Your SQL Journey: Module 2 Milestone

You have mastered single-sided and two-sided relational joining. Next: Cartesian matrices.

Session 01
Relational Model & Setup
COMPLETED ✓
Session 18
Anti-Joins & Absence
COMPLETED ✓
Session 19
FULL OUTER JOIN
YOU ARE HERE ●
Session 20
CROSS JOIN Matrices
UP NEXT →
Session 59
Production Capstone
FINAL STOP →

Next Session Preview: CROSS JOIN: All Combinations

Generating combinatorial grids, matrix reports, and exhaustive test combinations in PostgreSQL 18.

CARTESIAN MATRIX
Combinatorial Grids
Pairing every row from Table A with every row from Table B without an ON condition. M × N cardinality.
MATRIX REPORTING
Store × Category Gaps
Generating all possible store and product category combinations to detect missing retail stock matrices.
ACCIDENTAL TRAP
Missing Join Predicates
Why forgetting an ON clause produces accidental lakhs of rows and how to write intentional CROSS JOINs safely.
SNEAK PEEK • CATEGORY × STORE CARTESIAN MATRIX
SELECT
  c.category_name,
  s.store_name
FROM core.dim_category c
CROSS JOIN stores.stores s
WHERE s.store_id <= 3 AND c.category_id <= 4
ORDER BY c.category_name ASC, s.store_name ASC
LIMIT 12;
→ next   ← back   F fullscreen   H hide bars   N notes
1 / 41