Miscellaneous _ display duplicate records

Source: Internet
Author: User

Requirement

A table may have n records. How can I display duplicate records?

SQL> Create tablet1 (

2 ID number,

3 namevarchar2 (20)

4 );

 

Table created.

 

SQL> insert into T1 values (1, 'zhang yun ');

 

1 row created.

 

SQL> insert into T1 values (2, 'Ye yingcai ');

 

1 row created.

 

SQL> insert into T1 values (3, 'single-origin status ');

 

1 row created.

 

SQL> insert into T1 values (4, 'ant ');

 

1 row created.

 

SQL> insert into T1 values (5, 'Yao fengming ');

 

1 row created.

 

SQL> insert into T1 values (6, 'wu Cheng ');

 

1 row created.

 

SQL> insert into T1 values (7, 'zhang yun ');

 

1 row created.

 

SQL> insert into T1 values (8, 'wu Cheng ');

 

1 row created.

 

SQL> insert into T1 values (9, 'Ye yingcai ');

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

SQL> select * from T1;

 

ID name

------------------------------

1 Zhang Yun

2 ye yingcai

3 single country

4 Yi yaning

5. Yao fengming

6. Wu licheng

7 Zhang Yun

8. Wu licheng

9 ye yingcai

 

Analysis

First, we need to count the names and group duplicate names to find duplicate records.

SQL> select namefrom T1 group by name having count (name)> 1;

 

Name

--------------------

Wu licheng

Ye yingcai

Zhang Yun

 

Question 2

You have found out the duplicates, but how do I know that they are duplicates? If there are too many duplicates, you cannot see them directly.

SQL> select name, count (name) from T1 group by name having count (name)> 1;

(The total number is greater than 1, proving that there are duplicates)

 

Name count (name)

-------------------------------

Wu licheng 2

Ye yingcai 2

Zhang Yun 2

 

Third question

You have recorded repeated records, but how do I know what these records are?

SQL> select ID, name

2 from T1

3 where name in (Select name from T1 group by name having count (name)> 1)

4 order by name;

 

ID name

------------------------------

2 ye yingcai

9 ye yingcai

6. Wu licheng

8. Wu licheng

1 Zhang Yun

7 Zhang Yun

This article from the "happy life of cats and bears" blog, please be sure to keep this source http://bearlovecat.blog.51cto.com/1293914/1554409

Miscellaneous _ display duplicate records

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.