MySQL: DISTINCT reference
10 September 2023 (Updated 10 September 2023)
In a nutshell
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:
MySQL
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment