![]() |
VOOZH | about |
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;These examples show how to use DISTINCT to get unique values from a table.
Consider a table named employees with the following data:
To retrieve a list of unique departments, you can use the DISTINCT clause:
SELECT DISTINCT department
FROM employees;Output:
👁 Screenshot-2026-03-23-144409Suppose 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-144456DISTINCT 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-144543The following points highlight important aspects to consider when using the DISTINCT clause in MySQL.