MySQL Distinct Clause
Many times it happens that when you execute the SELECT statement, the data in the results is duplicated. For example, you select category table and show all its rows.
When you do this, it may be that the values of any 2 rows are same. This can happen in any column. This is called duplicate data.
Data duplicate can be due to many reasons. For example, if you accidentally entered the information of a employee twice, etc. If you want to have duplicate data in your results, you can use DISTINCT clause for it.
DISTINCT clause eliminates all duplicate rows from the result. The result is the only row show that came first in the result. All the remaining next duplicate rows are removed.
DISTINCT clause is defined before the list of columns and after the SELECT statement. It compares all the rows and then shows results. An example of this is being given below.
mysql> select distinct name from category;
When the above statement is executed, the category table displays a list of unique category names.