SQL DISTINCT Clause
Syntax
The DISTINCT clause in SQL is used to remove duplicate rows from the result set, returning only unique values.
-- Retrieve unique values from a single columnSELECT DISTINCT column1FROM table_name;
-- Retrieve unique rows based on multiple columnsSELECT DISTINCT column1, column2FROM table_name;Example
-- Retrieve unique departmentsSELECT DISTINCT departmentFROM employees;/* Output:| department ||-------------|| Sales || Marketing || HR |*/
-- Retrieve unique combinations of department and ageSELECT DISTINCT department, ageFROM employees;/* Output:| department | age ||-------------|-----|| Sales | 30 || Marketing | 25 || HR | 40 |*/