Toolpuffin

    Loading...

    Up and down to choose, Enter to open, Esc to close.

    How to learn SQL for beginners: SELECT, WHERE, GROUP BY and JOIN

    Updated December 2026

    Written by the Toolpuffin team. Tools in this guide are tested in the browser.

    SQL is the language for asking questions to a database and for adding or changing its data. This guide explains the basic commands in plain words, based on the documentation of SQLite, the small database that the practice course runs in your browser. You can try every step on a small database of pets and owners.

    Try the tool: Learn SQL

    What SQL and SQLite are

    SQLite describes itself as an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. Unlike most other SQL databases it has no separate server process: it reads and writes directly to ordinary disk files.

    Source: SQLite documentation: About SQLite

    The basics are shared, but the details are not. The SQLite documentation says that no two SQL database engines work exactly alike, and that every SQL implementation has its own peculiarities. So the SELECT, WHERE, GROUP BY and JOIN you learn here carry over to other databases, while things like how dates and limits are written can differ.

    Source: SQLite documentation: Quirks, Caveats, and Gotchas In SQLite

    Choose columns and filter rows

    A SELECT statement reads data from one or more tables. You name the columns you want after SELECT and the table after FROM, for example SELECT name, age FROM pets. A star (*) means all columns.

    The WHERE clause filters the rows. The SQLite documentation says that the input data is filtered using the WHERE clause expression, so only rows for which the expression is true are kept. For example, SELECT name FROM pets WHERE kind = 'dog' AND age > 4 returns the names of dogs older than 4.

    Source: SQLite documentation: SELECT

    Sort and limit the result

    ORDER BY puts the rows in a chosen order, and DESC reverses it. This is not a detail: the SQLite documentation says that if a SELECT that returns more than one row has no ORDER BY clause, the order of the rows is undefined. The LIMIT clause places an upper bound on the number of rows returned, so SELECT name, age FROM pets ORDER BY age DESC LIMIT 3 gives the three oldest pets.

    Source: SQLite documentation: SELECT

    Count, average and group

    Aggregate functions calculate one value from many rows. SQLite lists count, avg, sum, min and max among its built-in aggregate functions. count(*) returns the number of rows in the group, and avg() always returns a floating point value when there is at least one non-NULL input, even if all inputs are whole numbers.

    Source: SQLite documentation: Built-in aggregate functions

    GROUP BY combines rows into groups, and the aggregate is then worked out per group. The SQLite documentation calls a SELECT an aggregate query if it contains a GROUP BY clause or one or more aggregate functions. For example, SELECT kind, AVG(age) FROM pets GROUP BY kind gives one row per kind with its average age.

    Source: SQLite documentation: SELECT

    You want toWriteExample
    Pick columnsSELECTSELECT name, age FROM pets
    Keep matching rowsWHEREWHERE kind = 'cat'
    Sort and cut offORDER BY, LIMITORDER BY age DESC LIMIT 3
    Count rowsCOUNT(*)SELECT COUNT(*) FROM pets
    One result per groupGROUP BYGROUP BY kind

    Add and change data

    INSERT adds rows. The SQLite documentation says that INSERT INTO table VALUES(...) creates one or more new rows in an existing table, and that if you list no columns, the number of values must match the number of columns in the table. Naming the columns, as in INSERT INTO pets (id, name) VALUES (11, 'Bo'), is easier to read.

    Source: SQLite documentation: INSERT

    UPDATE changes values in existing rows. Be careful with the WHERE clause here: the documentation says that if an UPDATE statement has no WHERE clause, all rows in the table are modified.

    Source: SQLite documentation: UPDATE

    Combine tables with JOIN

    A JOIN combines rows from two tables, usually through a column that appears in both, such as the owner of a pet. You say how the rows belong together with ON, for example FROM pets JOIN owners ON pets.owner_id = owners.id. This matters: the SQLite documentation says that without an ON or USING clause the result of a join is simply the cartesian product of the two datasets, every row paired with every row.

    In SQLite, INNER JOIN, JOIN and a comma between tables are completely interchangeable, so you can write the shortest form.

    Source: SQLite documentation: SELECT

    Practise in your browser

    The course has 8 short lessons: look at a table, choose columns, WHERE, ORDER BY and LIMIT, COUNT, GROUP BY, INSERT and UPDATE, and JOIN. You write queries on a small database that runs in your browser and is made fresh every time you run a query, so you cannot break it. Each lesson has a hint and a full answer.

    More guides