MySQL Remove Duplicate Data: Quick Guide

In MySQL, you can use the DISTINCT keyword to eliminate duplicate data.

For example, suppose you have a table called employees, with a column named name. You can use the following query to retrieve data without duplicate names:

SELECT DISTINCT name FROM employees;

This will return a result set with duplicate names removed.

If you want to remove duplicate data from a table, you can use DELETE and temporary table.

Firstly, create a temporary table to store the results after removing duplicate data.

CREATE TABLE temp_table AS SELECT DISTINCT * FROM employees;

Next, delete the data from the original table.

DELETE FROM employees;

Finally, insert the data from the temporary table back into the original table.

INSERT INTO employees SELECT * FROM temp_table;

In this way, you have successfully removed the duplicates from the original table.

bannerAds