M. Kodirov

STAGE 04 / LESSON 02

SQL: read and change data

SQL describes the data you want and the changes you want to make.

THE IDEA

Understand it.

SELECT reads rows; WHERE filters them; ORDER BY defines an ordering. INSERT, UPDATE and DELETE change data. Use a transaction when multiple related changes need to succeed or fail as a unit.

When values come from users, use the parameter facilities provided by your database driver or ORM. Do not concatenate user input into SQL strings: that can allow SQL injection.

SEE IT IN CONTEXT

Find open tasks

SELECT id, title, status
FROM tasks
WHERE status = 'open'
ORDER BY id DESC
LIMIT 20;

The filter selects open tasks, the ordering puts larger IDs first, and LIMIT bounds the number of returned rows.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitLab

Documentation checked November 2026

Review queries for performance

GitLab's database guidance explains how its developers inspect and improve database queries.

  1. Application query
  2. Database
  3. Rows and execution details

What to learn: SQL expresses which rows are needed; measuring a real query reveals whether it remains practical as data grows.

Read the source: GitLab database query performance

GitHub

GitHub engineering, 2015

Study a MySQL workload

GitHub's engineering article demonstrates analyzing database workloads with MySQL's Performance Schema.

  1. SQL workload
  2. MySQL Performance Schema
  3. Workload analysis

What to learn: Observe actual query patterns before choosing an optimization. This example uses MySQL, not PostgreSQL.

Read the source: GitHub MySQL workload analysis

TRY IT YOURSELF

Practice.

How would you return only completed tasks?

Show one possible answer

Change the predicate to WHERE status = 'done'. In application code, pass a user-supplied status as a parameter instead of concatenating it into SQL.

GO DEEPER

Official references.