How do I remove duplicate data or rows from a MySQL query?
If output from a MySQL query contains duplicate data or row and if you would like to remove the same use DISTINCT.
DISTINCT combined with ORDER BY needs a temporary table in many cases. Consider following query:
mysql> SELECT firstname FROM address;
If you need unique firstname i.e remove duplicate contains type the command:
mysql> SELECT DISTINCT firstname FROM address;
You can use DISTINCT with multiple column as follows:
mysql> SELECT DISTINCT firstname, city FROM address;
For DISTINCT optimization please see this help page.Share this tutorial on: