Mysql method to remove duplicate records: 1. Use the "select distinct name from a where statesign=0" command to remove duplicate records; 2. Use the "select name from a where statesign=0 group by name" command to remove Duplicate records.
The operating environment of this tutorial: Windows 10 system, MySQL version 5.7, Dell G3 computer.
mysql How to remove duplicate records?
mysql query to remove duplicate records
1: Use distinct
select distinct name from a where statesign=0
to query the name field in table a to remove duplicate records
2: Use group by
select name from a where statesign=0 group by name
to query the name field in table a, group it, and remove duplicate records
When using distinct, it must be placed in the first position otherwise an error will be reported
Related extensions :
DISTINCT is actually very similar to the implementation of GROUP BY operation, except that only one record is taken out from each group after GROUP BY. Therefore, the implementation of DISTINCT and the implementation of GROUP BY are basically the same, and there is not much difference. It can also be achieved through loose index scan or compact index scan. Of course, when DISTINCT cannot be completed using only indexes, MySQL can only be completed through temporary tables.
However, one difference from GROUP BY is that DISTINCT does not need to be sorted. In other words, if the Query that is just a DISTINCT operation cannot complete the operation using only the index, MySQL will use the temporary table to "cache" the data, but will not perform filesort operations on the data in the temporary table.
Of course, if we also use GROUP BY and group when performing DISTINCT, and use aggregate function operations similar to MAX, filesort cannot be avoided.
Recommended learning: "MySQL Video Tutorial"
The above is the detailed content of How to remove duplicate records in mysql. For more information, please follow other related articles on the PHP Chinese website!