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

    SELECT: choosing columns

    Specific columns, new names with AS, calculations, and DISTINCT.

    8 minutes3 games

    Instead of *, list just the columns you need, separated by ,. The order you write them is the order they appear.

    SQL
    SELECT name, xp
    FROM students;

    Calculations and new names

    You can calculate inside SELECT itself; the result is a new column that isn't stored in the table. AS gives it a clear name (an alias).

    SQL
    SELECT title,
           price,
           price * 0.8 AS sale_price,
           hours * 60 AS minutes
    FROM courses;

    FROM courses: every row

    For each row: compute price * 0.8

    Return only the columns you asked for

    DISTINCT: no repeats

    SQL
    SELECT DISTINCT city
    FROM students;

    Important

    SELECT * is fine while exploring, but in application code name the columns: less data travels over the network, and the code doesn't break when someone adds a column later.

    Complete the code

    Complete the query so each city appears only once.

    SELECT  city FROM students;

    Quick question

    How many rows does SELECT DISTINCT city FROM students return? (Cities: Cairo ×3, Alexandria ×2, Giza ×2, Mansoura ×1)

    Interview question

    Why avoid SELECT * in production code?

    Exercise

    Show title and hours for every course, but name the hours column duration.

    Expected result:
    title | duration
    HTML & CSS | 12
    JavaScript | 30
    Python | 28
    SQL | 16
    React | 24
    C++ | 36
    SQL
    SELECT title
    FROM courses;

    Learn more from

    • PostgreSQL docs: Querying a Tablepostgresql.org
    • SQLite: The SELECT statementsqlite.org
    • Use The Index, Luke: Index-only scanuse-the-index-luke.com

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousWhat are SQL and databases?NextWHERE: filtering rows
    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.