SQL statement for deleting duplicate data and searching duplicate data (1/4)

Source: Internet
Author: User

Example 1: The table has a primary key (a field that can be uniquely identified) and the field is of the numerical type.

Example 1 test data/* Table Structure */
Drop table if exists 't1 ';
Create table if not exists 't1 '(
'Id' int (1) not null auto_increment,
'Name' varchar (20) not null,
'Add' varchar (20) not null,
Primary key ('id ')
) Engine = innodb;

/* Insert Test Data */
Insert into 't1' ('name', 'add') values
('Abc', "123 "),
('Abc', "123 "),
('Abc', "321 "),
('Abc', "123 "),
('Xzy ', "123 "),
('Xzy ', "456 "),
('Xzy ', "456 "),
('Xzy ', "456 "),
('Xzy ', "789 "),
('Xzy ', "987 "),
('Xzy ', "789 "),
('Ijk "," 147 "),
('Ijk "," 147 "),
('Ijk "," 852 "),
('Opq', "852 "),
('Opq', "963 "),
('Opq', "741 "),
('Tpk', "741 "),
('Tpk', "963 "),
('Tpk', "963 "),
('Wher', "546 "),
('Wher', "546 "),
('Server', "546 ");

Select * from 't1 ';
+ ---- + ------ + ----- +
| Id | name | add |
+ ---- + ------ + ----- +
| 1 | abc| 123 |
| 2 | abc| 123 |
| 3 | abc| 321 |
| 4 | abc| 123 |
| 5 | xzy | 123 |
| 7 | xzy | 456 |
| 6 | xzy | 456 |
| 8 | xzy | 456 |
| 9 | xzy | 789
| 10 | xzy | 987 |
| 11 | xzy | 789 |
| 12 | ijk | 147 |
| 13 | ijk | 147
| 14 | ijk | 852 |
| 15 | ops | 852 |
| 16 | ops | 963 |
| 17 | opq | 741 |
| 18 | tprimary | 741 |
| 19 | tprimary | 963 |
| 20 | tprimary | 963 |
| 21 | Lower | 546 |
| 22 | Lower | 546 |
| 23 | once | 546 |
+ ---- + ------ + ----- +
23 rows in set (0.00 sec) 1 2 3 4

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.