Let’s Get Certified
Module 01 / 04 · Read and combine rows

Filter and sort a result

Choose columns, filter unknown values, and make a top-N result repeatable.

Find tickets that need estimates

Open an empty SQLite database in the SQLite shell or the linked SQLite Fiddle. Run the setup below once. Keep this database open for the remaining exercises. Each ticket belongs to a team. A missing estimate is stored as NULL. Dates use the same year-month-day format throughout.

CREATE TABLE team (
  id INTEGER PRIMARY KEY, name TEXT NOT NULL
);
CREATE TABLE ticket (
  id INTEGER PRIMARY KEY, team_id INTEGER REFERENCES team(id),
  opened TEXT NOT NULL, state TEXT NOT NULL, hours INTEGER
);
INSERT INTO team VALUES (1,'North'), (2,'South'), (3,'West');
INSERT INTO ticket VALUES
  (11,1,'2026-04-01','open',3),
  (12,1,'2026-04-02','open',NULL),
  (13,1,'2026-04-02','closed',5),
  (14,2,'2026-04-03','closed',2);

Select rows and establish their order

SELECT id, opened, hours
FROM ticket
WHERE state = 'open'
ORDER BY opened DESC, id DESC
LIMIT 2;

Expect ticket 12 followed by 11. ORDER BY chooses the newest date first. The unique ID breaks ties. LIMIT alone gives no ordering guarantee. A SELECT lists exactly the fields a report needs.

Try it

Find open tickets without an estimate. Add AND hours IS NULL to the filter. Only ticket 12 remains. hours = NULL produces an unknown comparison and cannot select that row. An estimate of zero, if present, is a known value.

Open SQLite Fiddle · SELECT reference

Knowledge check

Filter and sort a result quiz

Answer 3 questions. Check each answer for an explanation.