MySQL DISTINCT Clause (original) (raw)

Last Updated : 23 Mar, 2026

The SELECT DISTINCT statement is used to retrieve unique values from one or more columns in a table. It removes duplicate records and returns only distinct results.

**Syntax:

SELECT DISTINCT column1, column2, ...FROM table_nameWHERE condition;

Examples of DISTINCT Clause

These examples show how to use DISTINCT to get unique values from a table.

Example 1: Selecting Distinct Values from a Single Column

Consider a table named employees with the following data:

Screenshot-2026-03-23-144241

To retrieve a list of unique departments, you can use the DISTINCT clause:

SELECT DISTINCT department FROM employees;

**Output:

Screenshot-2026-03-23-144409

Example 2: Selecting Distinct Values From Multiple Columns

Suppose you want to retrieve unique combinations of department and employee_name. You can modify the query to include multiple columns:

SELECT DISTINCT department, employee_name FROM employees;

**Output:

Screenshot-2026-03-23-144456

Example 3: Using DISTINCT with WHERE Clause

DISTINCT clause can be combined with the WHERE clause to filter results. For example, to get unique departments that start with 'S':

SELECT DISTINCT department FROM employees WHERE department LIKE 'S%';

**Output:

Screenshot-2026-03-23-144543

**Things to Remember When Using DISTINCT

The following points highlight important aspects to consider when using the DISTINCT clause in MySQL.