SQL Tutorial 0/85 lessons ~6 min read Lesson 80

    SQL Debugging Exercises

    Bug-hunting practice: queries that look right but return wrong data.

    Course progress0%
    Focus
    6 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Bug-hunting practice: queries that look right but return wrong data. Topics: NULL handling, outer joins, GROUP BY pitfalls, datetime mistakes.

    Understanding the topic

    Core concepts to understand:

    • NOT IN with NULL → empty result.
    • = NULL never matches.
    • LEFT JOIN + WHERE on right side becomes INNER.
    • SUM over LEFT JOIN counts NULL as 0 — sometimes wrong.
    • Date math across DST.

    Syntax reference

    Visual workflow / architecture:

    bash
    Bug class Symptom
    NULL semantics Empty / wrong totals
    JOIN turning into INNER Missing rows in report
    Sloppy GROUP BY Bad totals
    TIMESTAMP w/o TZ Off-by-N hours

    Real-world use

    These bugs hit production routinely. Spotting them quickly is a senior superpower.

    Best practices

    • Always handle NULL explicitly.
    • Push WHERE on right-side cols into ON.
    • Use TIMESTAMPTZ.

    Hands-on exercise

    Interview preparation — practice these questions:

    • Q1. Why does NOT IN with NULL return empty?
    • Q2. Find the bug in this LEFT JOIN.
    • Q3. GROUP BY pitfalls.
    • Q4. Datetime + DST bug.
    • Q5. Float vs NUMERIC for money.
    Ready to mark this lesson complete?Track your journey across the entire course.