MySQL DISTINCT: Remove Duplicate Records

In MySQL, you can use the DISTINCT keyword to perform a query that removes duplicates and returns unique values. Here is a simple example:

SELECT DISTINCT column1, column2 
FROM table_name;

The example above will return a unique combination of column1 and column2 columns in the table_name table, removing duplicate records.

Additionally, you can use GROUP BY combined with aggregate functions to achieve a distinct query. For example:

SELECT column1, MAX(column2)
FROM table_name
GROUP BY column1;

This method groups column1 and selects the largest value of column2 in each group, achieving a de-duplication effect.

bannerAds