Practice Free
HardJoins High Frequency

General Ledger Bank Reconciliation with FULL OUTER JOIN

Frequently Asked By:StripeCoinbaseBloomberg
Interactive In-Browser Workspace

Practice this problem on live schema tables in PostgreSQL 16 WASM with instant row verification and visual EXPLAIN plans.

Solve in Workbench

Problem Statement

Join `internal_ledger` with `bank_statement_lines` using a `FULL OUTER JOIN` on `transaction_ref`. Calculate: 1. `COALESCE(l.transaction_ref, b.transaction_ref)` AS `ref_code` 2. `l.ledger_amount` 3. `b.statement_amount` 4. `reconciliation_status`: - When `l.transaction_ref IS NULL` THEN `'Missing in Ledger'` - When `b.transaction_ref IS NULL` THEN `'Missing in Bank'` - ELSE `'Matched'` Order results by `ref_code` ascending.

Why Technical Interviewers Ask This

Accounting must reconcile internal ledger records against external bank statements. Any transaction appearing on only one side must be flagged as either 'Missing in Bank' or 'Missing in Ledger'.

Common Pitfalls & Interview Traps

Forgetting required sorting and deterministic tie-breaking.
Not accounting for NULL or zero-value denominators during calculations.
Using inefficient quadratic subqueries instead of single-pass joins constructs.

Canonical Modern SQL Solution

PostgreSQL 16 / ANSI SQL
SELECT 
        COALESCE(l.transaction_ref, b.transaction_ref) AS ref_code,
        l.ledger_amount,
        b.statement_amount,
        CASE 
          WHEN l.transaction_ref IS NULL THEN 'Missing in Ledger'
          WHEN b.transaction_ref IS NULL THEN 'Missing in Bank'
          ELSE 'Matched'
        END AS reconciliation_status
      FROM internal_ledger l
      FULL OUTER JOIN bank_statement_lines b ON l.transaction_ref = b.transaction_ref
      ORDER BY ref_code ASC;
Approach Breakdown
This query addresses the problem requirements by filtering and structuring data in Joins. It meets the target criteria: Reconciliation table classifying each transaction as Matched, Missing in Bank, or Missing in Ledger.

Edge Cases to Verbally Clarify with Your Interviewer

The dataset contains zero matching records (must return valid empty result without crashing).
Multiple records tie on sorting criteria (must evaluate tie-breaking order deterministically).
Foreign keys or secondary attributes have NULL values.

Frequently Asked Follow-Up Questions

What makes this question a favorite among Stripe and Coinbase interviewers?

Interviewers use this problem to test whether candidates write defensive, scalable Joins queries that run efficiently on multi-million row production databases without excessive memory usage.

How does the query optimizer execute this query?

Using single-pass table scans with index lookups or sort buffers. Running EXPLAIN (ANALYZE, BUFFERS) in the DB Exercises workbench visualizes the execution nodes and buffer hit cache.

More FAANG SQL Interview Questions

View all questions