The SELECT DISTINCT statement in SQL is used to retrieve unique values from a column or set of columns in a table. It helps to eliminate duplicate rows from the result set, ensuring that only distinct values are displayed.
SQL Select Distinct Syntax
SQL
x
1
SELECT DISTINCT column1, column2, ...
2
FROM table_name;
SQL Select Distinct Examples
SQL Select Distinct Selecting Unique Values from a Single Column Example
This query retrieves a list of distinct specialty values from the doctors table. If multiple doctors have the same specialty, it will only show that specialty once.
SQL
1
1
SELECT DISTINCT specialty
2
FROM Doctors;

SQL Select Distinct Selecting Unique Combinations from Multiple Columns
This query retrieves unique pairs of first_name and last_name.
SQL
1
1
SELECT DISTINCT first_name, last_name
2
FROM Doctors;

SQL Select Distinct Visual Diagram
