Home > Database > Mysql Tutorial > body text

MySQL 删除表中重复记录

WBOY
Release: 2016-06-07 17:25:03
Original
984 people have browsed it

MySQL 删除表中重复记录,本文针对的MySQL版本是:5.0.22-community-nt。

MySQL 删除表中重复记录,,本文针对的MySQL版本是:5.0.22-community-nt。

1. 为表folder新建一个临时表folder_tmp

create table folder_tmp as select * from folder group by serverIp, userId, name, path;

这里根据serverIp, userId, name, path分组之后,表folder_tmp中留下的是主键id靠前的数据

2. 删除原来的表

drop table folder

3. 重命名表

alter table folder_tmp rename folder

4. 最后别完了创建外键和索引以及主键等,因为第一步骤创建的临时表,不包含原表的外键、索引和主键

linux

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 admin@php.cn
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!