MySQL DISTINCT Clause
The DISTINCT clause filters and removes duplicate records from the resultset; hence, unique records will be left. For example, if one cell value is repeated multiple times in that same column, that value will be shown only once in the resultset. Please note that the DISTINCT clause only removes the duplicate values from the resultset and NOT the database.
The above figure demonstrates the working of MySQL SELECT DISTINCT, as it excluding all the duplicate records and fetching only single instances of each type.
Syntax:
SELECT DISTINCT column_names FROM Table_Name;
Let’s look at the following example
Assuming that we have a database called – ‘w3wiki‘ and a table called – ‘employees‘ in it. Fetching the data without using the DISTINCT keyword fetches us all the records that are present in the ‘employees‘ table. (Our table contains redundant values)
But when we apply the distinct keyword using the following query:
SELECT DISTINCT * FROM employees;
Output
MySQL DISTINCT Clause
MySQL is a relational database management system that can store data and we can query the stored data using SQL. SQL is a standard language to manipulate the database. The data fetching process can be applied with many filters as we might need only some specific data, or we might want to exclude some data then we can apply a filter using something called – ‘CLAUSE‘ in SQL. In this article, we’ll be discussing the ‘DISTINCT‘ clause.