Home  >  Article  >  Backend Development  >  How to delete duplicate fields in a data table using sql statement, sql statement_PHP tutorial

How to delete duplicate fields in a data table using sql statement, sql statement_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:071133browse

How to delete duplicate fields in a data table using sql statement, sql statement

 大家都可能遇到字段重复的情况,网上很多人在找方法,也给出了一些方法,但是有的方法是误导大家,铁牛写出以下方法,方便大家使用

1. Filter out duplicate fields through group by and create a temporary table tmp

create table tmp as select max(id) as col1 from www group by dfdfd;

2. Use the not in condition to filter out the column col1 that is not in the temporary table from the deduplication table object, and perform the not in deletion operation

delete from www where id not in (select col1 from tmp); 

 3. Delete temporary table

drop table tmp;

Welcome to join the PHP technology and workplace exchange group: 383730534

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/952777.htmlTechArticleHow to delete duplicate fields in a data table using sql statements. Everyone may encounter duplicate fields in sql statements. There are many on the Internet People are looking for ways, and some methods have been given, but some methods are wrong...
Statement:
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 admin@php.cn