Home > Database > Mysql Tutorial > body text

How to remove duplicate records in mysql

藏色散人
Release: 2023-02-16 09:56:11
Original
3364 people have browsed it

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.

How to remove duplicate records in mysql

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!