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 9 of 20

    INNER JOIN

    Combine rows from two tables where they match.

    9 minutes3 games

    JOIN pairs each row of one table with the rows that match it in another, using a condition written after ON. Usually that's "foreign key = primary key".

    SQL
    SELECT s.name, e.course_id, e.progress
    FROM students AS s
    JOIN enrollments AS e ON e.student_id = s.id
    WHERE s.city = 'Cairo';

    s and e are short table names (aliases); they save typing and show where each column comes from. If a column exists in both tables (like id) you must prefix it.

    studentsenrollmentsIn the result?

    Laila (id 1)

    3 rows (1,1) (1,2) (1,5)

    yes, 3 times

    Omar (id 3)

    1 row (3,3)

    yes, once

    Mariam (id 6)

    2 rows

    yes, twice

    Youssef (id 5)

    none

    no, gone

    A student repeats once per enrollment; one with none disappears.

    Important

    Plain JOIN means INNER JOIN: a row with no match on the other side vanishes from the result. Youssef and Hana have no enrollments, so they don't appear. To keep them you need LEFT JOIN (next lesson).

    What's the output?

    SELECT COUNT(*) AS rows
    FROM students s
    JOIN enrollments e ON e.student_id = s.id;

    What will this code print?

    Spot the bug

    The result is wrong: course names that don't belong to these students. Where's the bug?

    Interview question

    Explain the types of JOIN.

    Exercise

    Get the names of students enrolled in course 3 (Python), in alphabetical order.

    Expected result:
    name
    Ali
    Nour
    Omar
    SQL
    SELECT s.name
    FROM students s
    

    Learn more from

    • PostgreSQL docs: Joins between tablespostgresql.org
    • Mode: SQL joinsmode.com
    • Wikipedia: Join (SQL)en.wikipedia.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousKeys and relationshipsNextLEFT JOIN: leave nobody out
    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.