Mysql-& gt; SQL statement: delete duplicate data

Source: Internet
Author: User
Tags mysql code

Mysql-> SQL statement: An SQL statement is used to delete duplicate data in the table. Occasionally, when I talked to my colleagues about this issue, I wrote the code for your reference ~ // Data preparation Mysql code drop table t_user; create table t_user (id int (5) not null auto_increment, username varchar (10), age int (3 ), primary key (id); insert into t_user (username, age) values ('aaa', 20); insert into t_user (username, age) values ('aaa ', 20); insert into t_user (username, age) values ('aaa', 20); insert into t_user (username, age) values ('bbb', 20 ); insert into t_user (username, age) values ('bbb ', 20); insert into t_user (username, age) values ('ccc', 20); insert into t_user (username, age) values ('ccc ', 20); insert into t_user (username, age) values ('ddd', 20); insert into t_user (username, age) values ('ddd ', 20); DELETE statement: Mysql code DELETE t FROM t_user t, (SELECT min (id) AS ttid, username FROM t_user t2 group by t2.username) AS tt WHERE t. id> tt. ttid and t. username = tt. username;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.