SELECT DISTINCT

SELECT with DISTINCT on one column

In this exercise we query the orders table and return only the distinct values in the order_id column.

SELECT DISTINCT order_id
FROM orders;
Run in terminal

The query should return 830 rows

SELECT with DISTINCT including multiple columns

In this exercise we query the orders table and return only the distinct values based on combining the specified columns.

SELECT DISTINCT order_id,
customer_id,
employee_id
FROM orders;
Run in terminal

The query should return 830 rows

SELECT with DISTINCT ON expression

In this exercise we query the orders table and ask to keep just the first row of each group of duplicates.

SELECT DISTINCT ON (employee_id)employee_id AS id_number,
customer_id
FROM orders
ORDER BY id_number,
customer_id;
Run in terminal

The query should return 9 rows