MySQL Distinct clause is used to remove duplicate values from the result dataset.
The Basic Syntax of the MySQL Distinct is as follows
SELECT DISTINCT <column-names>
FROM <table_name>;
To get the distinct values from the data for a single column, we do:
select distinct rating from film;
When we use distinct with multiple columns, MySQL will return all the records in the dataset that are a unique combination of both the columns.
select distinct rating,title from film
order by rating desc;
When we try to get all the distinct values in a column that contains NULL values, we get a single row with NULL and the rest of the unique values. NULL values are not repeated in the result set.
select distinct city_id from address;