How to remove duplicate data in MySQL using DISTINCT?

In MySQL, you can use the DISTINCT keyword to remove duplicates from the data.

For instance, let’s say we have a table named “students” which includes students’ names and class information. If we want to retrieve unique class information, we can use the following query statement:

SELECT DISTINCT class FROM students;

This will generate a list of unique class information.

If we want to retrieve unique combinations of names and classes, we can use the following query statement:

SELECT DISTINCT name, class FROM students;

This will return a list of unique combinations of names and classes.

bannerAds