Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    SQLSQL

    First questions to the data

    • What are SQL and databases?
    • SELECT: choosing columns
    • WHERE: filtering rows
    • ORDER BY and LIMIT: sort and take the top

    Summarizing and grouping

    • Aggregates: COUNT, SUM, AVG
    • GROUP BY and HAVING
    • CASE, COALESCE and text functions

    Joining tables

    • Keys and relationships
    • INNER JOIN
    • LEFT JOIN: leave nobody out
    • Three-table joins and self joins
    • Subqueries and CTEs

    Building tables and changing data

    • CREATE TABLE and constraints
    • INSERT, UPDATE and DELETE
    • Transactions: all or nothing
    • SQL injection: the most dangerous mistake

    Professional level

    • Indexes: why is my query slow?
    • Window functions: rankings and totals without losing rows
    • Designing tables: normalization
    • Project: analytics for a learning platform
    SQL

    Joining tables · Lesson 10 of 20

    LEFT JOIN: leave nobody out

    Keep every row of the first table and find what has no match.

    9 minutes2 games

    LEFT JOIN keeps every row of the left table, even those with no match. The columns from the right side are NULL for those rows.

    SQL
    SELECT s.name, COUNT(e.course_id) AS courses
    FROM students s
    LEFT JOIN enrollments e ON e.student_id = s.id
    GROUP BY s.id, s.name
    ORDER BY courses DESC, s.name;

    Youssef and Hana appear with 0. Note we counted COUNT(e.course_id), not COUNT(*): their row exists, but course_id is NULL, and COUNT skips NULL.

    Who has no enrollments at all?

    SQL
    SELECT s.name
    FROM students s
    LEFT JOIN enrollments e ON e.student_id = s.id
    WHERE e.student_id IS NULL;

    LEFT JOIN: every student, with NULL beside those without enrollments

    WHERE e.student_id IS NULL

    Only the unmatched remain: Youssef and Hana

    This pattern is an anti-join, a favourite interview question.

    Important

    Put a condition on the right table in WHERE (like WHERE e.progress > 50) and the NULL rows are dropped, silently turning the LEFT JOIN into an INNER JOIN. To filter the right side while keeping every left row, put the condition in ON.

    Spot the bug

    We want every student, with the courses they're more than halfway through. But Youssef and Hana vanished. Why?

    Interview question

    How do you find customers who never placed an order? Give more than one way.

    Exercise

    Get the title of courses that no student is enrolled in.

    Expected result:
    title
    C++
    SQL
    SELECT c.title
    FROM courses c
    

    Learn more from

    • PostgreSQL docs: Joined tables (outer joins)postgresql.org
    • Modern SQL: NULLmodern-sql.com
    • Use The Index, Luke: Join operationsuse-the-index-luke.com

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousINNER JOINNextThree-table joins and self joins
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.