Skip to content
ohsudo, Home

SELECT, WHERE and ORDER BY

Every query starts here: which columns, from which table, which rows, and in what order. The tables hold a small company's staff.

● A real database, running in your browser. Nothing you type leaves this page.

Exercise 1 of 6

Everything in a table

SELECT says what you want, and FROM says where it is. * means all columns. It's fine for a quick look, while real applications should name their columns.

Your task

Show every column of every row in departments.

Tables and columns
    or Ctrl+Enter

    What you'll practice

    1. Everything in a table. SELECT says what you want, and FROM says where it is. * means all columns. It's fine for a quick look, while real applications should name their columns.
    2. Only some columns. Name the columns you want, separated by commas.
    3. Only some rows. WHERE keeps the rows where a condition is true.
    4. Text goes in quotes. Text values go in single quotes. In PostgreSQL, double quotes mean a column name, and that's a classic error. Text values go in single quotes. SQLite may accept double quotes as text too, but that's a leniency you shouldn't rely on, as other databases treat them as column names.
    5. Sort and limit. Without ORDER BY, the order isn't guaranteed, whatever it looks like. DESC means largest first, and LIMIT keeps the first few rows.
    6. No duplicates. DISTINCT removes repeated rows from the result.

    See also