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

Return Distinct Values

Use `DISTINCT` to remove duplicate rows from a result set.

Docker-validated Not currently validation-green

List unique status values

DISTINCT applies after the selected columns are evaluated, so duplicate values collapse to one row in the result.

Rows loaded before the example query runs.
Setup
CREATE TABLE orders (id INT, status VARCHAR(20));

INSERT INTO
  orders (id, status)
VALUES
  (1, 'new'),
  (2, 'shipped'),
  (3, 'new');
Shared across supported engines.
SQL
SELECT DISTINCT
  status
FROM
  orders
ORDER BY
  status;
Returned rows for the shared example.
status
new
shipped

The result shape is identical because the query orders the deduplicated values explicitly.

Where this command helps.

  • listing the unique values available in a column
  • removing duplicate rows from a lookup-style result set

What the command is doing.

DISTINCT operates on the selected columns, not the underlying table rows. It is useful when you want a unique list of values such as categories, statuses, or regions.