SQL: DISTINCT
10 September 2023 (Updated 18 May 2025)
What is the DISTINCT keyword?
The DISTINCT keyword is used in conjunction with the SELECT statement to eliminate duplicate rows from a result set.
What is regarded as a duplicate row depends on the columns you pass to DISTINCT.
DISTINCT without any columns
SELECT DISTINCT * FROM students;
Two rows are duplicates if every column in both rows are the same.
DISTINCT with a single column
SELECT DISTINCT first_name FROM students;
Two rows are duplicates if the first_name column of both rows is the same.
DISTINCT with multiple columns
SELECT DISTINCT first_name, last_name FROM students;
Two rows are duplicates if the first_name and last_name columns of both rows is the same.
Tagged:
SQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment