What is the purpose of “distinct” in MySQL?
In MySQL, the DISTINCT keyword is used to retrieve unique data records, removing any duplicates from the query result set and returning only unique records.
For example, suppose there is a table named “employees” that contains the following data:
If the following query is executed:
SELECT DISTINCT name FROM employees;
We will get the following outcome set:
denomination
John and Alice
The DISTINCT keyword removes duplicate name values, returning only unique name values.
In summary, the DISTINCT keyword is used to eliminate duplicate records from the query result set, in order to only return unique records.