Introduction
Use DISTINCT to get only unique values from a list, removing any duplicates.
SELECT DISTINCT column_name FROM table_name;
SELECT DISTINCT country FROM customers;
SELECT DISTINCT product_name FROM products;
SELECT DISTINCT city, state FROM addresses;
CREATE TABLE employees (id INT, name VARCHAR(50), department VARCHAR(50)); INSERT INTO employees VALUES (1, 'Alice', 'HR'), (2, 'Bob', 'IT'), (3, 'Charlie', 'HR'), (4, 'Diana', 'Finance'); SELECT DISTINCT department FROM employees;
DISTINCT do in a query?Customers?Orders with a column Product containing values: ['Pen', 'Pen', 'Book', 'Notebook', 'Book'], what will the query SELECT DISTINCT Product FROM Orders; return?Customers table?SELECT DISTINCT name, age FROM Customers;Sales with columns Region and SalesPerson. You want to find all unique salespersons regardless of region. Which query gives the correct result?Pass the test and this pattern moves unknown