sqlcmd.net validated sql reference
beginner filtering MySQL MariaDB SQL Server PostgreSQL SQLite

Filter Rows With WHERE

Return only rows that match a condition, with explicit ordering for stable output.

Docker-validated Not currently validation-green

Find rows for one city

WHERE city = 'London' trims the result set before sorting, so only matching rows appear in the final output.

Rows loaded before the example query runs.
Setup
CREATE TABLE offices (id INT, city VARCHAR(50));

INSERT INTO
  offices (id, city)
VALUES
  (1, 'London'),
  (2, 'Berlin'),
  (3, 'London');
Shared across supported engines.
SQL
SELECT
  id,
  city
FROM
  offices
WHERE
  city = 'London'
ORDER BY
  id;
Returned rows for the shared example.
idcity
1London
3London

Validated on all four engines with the same column names and row order.

Where this command helps.

  • finding rows that match a business rule
  • reducing a dataset before sorting or aggregation

What the command is doing.

Use WHERE to narrow a result set before it reaches the client. For examples, pair it with ORDER BY so the expected output stays deterministic.