Find a record with the same column value in the table, and the SQL

Source: Internet
Author: User
For example, if a table is like this, the ID is the primary key and the table is auto-incrementing:
Column name: Id Columna columnb columnc
Column value: 1 A asdfd afdsf
2 B sdfafsd 080dfs
3 A dfsafja08 90879.
4 C fds934 fsdaf
5 B safsfsd fd86fsdaf
The query results after the SQL statement is executed are as follows:
Column name: Id Columna columnb columnc
Column value: 1 A asdfd afdsf
2 B sdfafsd 080dfs
That is to say, we need to find a record where Columna has duplicate values and only one record is repeated. For example, if Columna is A, there are two records, the retrieved Record ID = 1 or ID = 3. The same applies to colunma = B.
The following is an SQL statement:
Select * from table where ID in (select Min (ID) from Table group by Columna)

The above statement was put forward by me, and then the "Guangdong. Net" QQ Group discussed it collectively. Finally, it was written by Jerry, and he did not dare to seek help.

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.