Oracle finds records with the same data of several fields in the table

Source: Internet
Author: User

Oracle finds records with the same data in several fields in the table [SQL] create table student (id number primary key, name varchar2 (20), gender varchar2 (2); create table student, contains two main fields: name and gender. insert several data records. [SQL] ID NAME GENDER -- ------------------ -- 1 Zhang San male 2 Li Si male 3 Li Si male 4 Li Si female 5 Zhang San female 6 Zhang San male can see that the name of id () is the same as gender, the name and gender of id (2, 3) are the same. Request: list records with the same name and gender. Write SQL [SQL] SQL> SELECT s. name, s. gender 2 FROM student s 3 WHERE (select count (*) 4 FROM student 5 WHERE name = s. name and gender = s. gender)> 1) 6 order by name, gender DESC, in the where clause, subqueries are used to separate two fields as filter conditions, and then all records are obtained directly.

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.