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

    First questions to the data · Lesson 3 of 20

    WHERE: filtering rows

    Comparisons, AND/OR, IN, BETWEEN, LIKE, and the NULL trap.

    10 minutes3 games

    WHERE picks rows (just as SELECT picks columns). The database tests the condition on every row and keeps only those where it's true.

    SQL
    SELECT name, city, xp
    FROM students
    WHERE city = 'Cairo';
    ConditionMeaning

    xp = 90

    equals

    xp <> 90

    not equal (or !=)

    xp >= 150

    greater than or equal

    xp BETWEEN 100 AND 300

    100 to 300, both ends included

    city IN ('Cairo', 'Giza')

    one of the list

    name LIKE 'K%'

    starts with K (% = any characters)

    xp IS NULL

    has no value

    Combine conditions with AND (both must hold) and OR (either is enough). When mixing them, use brackets: AND binds before OR, like multiplication before addition.

    SQL
    SELECT name, city, xp
    FROM students
    WHERE xp > 100
      AND (city = 'Cairo' OR city = 'Giza');

    The NULL trap

    NULL means "unknown", not zero and not empty text. Youssef's xp is NULL. Run these two and compare:

    SQL
    SELECT name FROM students WHERE xp = NULL;
    
    SELECT name FROM students WHERE xp IS NULL;

    Important

    Any comparison with NULL gives NULL (neither true nor false), even NULL = NULL. That's why WHERE xp = NULL returns no rows. Always use IS NULL and IS NOT NULL.

    LIKE in SQLite and MySQL ignores case for English letters, but in PostgreSQL it doesn't. There, use ILIKE for a case-insensitive search.

    What's the output?

    SELECT name
    FROM students
    WHERE xp BETWEEN 150 AND 300;

    What will this code print?

    Spot the bug

    This query should find students with no XP yet, but it returns nothing. Where's the bug?

    Interview question

    Why does WHERE col = NULL return no rows? What is "three-valued logic"?

    Exercise

    Get name, city and xp for students in Alexandria or Giza who also have 150 XP or more.

    Expected result:
    name | city | xp
    Karim | Alexandria | 150
    Nour | Giza | 410
    Ali | Giza | 180
    SQL
    SELECT name, city, xp
    FROM students
    WHERE ;

    Learn more from

    • PostgreSQL docs: Comparison operatorspostgresql.org
    • PostgreSQL docs: Pattern matching (LIKE)postgresql.org
    • Modern SQL: The three-valued logic of SQLmodern-sql.com
    • SQLite: NULL handlingsqlite.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousSELECT: choosing columnsNextORDER BY and LIMIT: sort and take the top
    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.