SQL statement Query table repeating field and display field repeating number of bars

Source: Internet
Author: User

Today we share two SQL statements about querying repeating fields in a table and displaying the number of repeating bars for that field.

1.select * FROM table name where column name in (select Column name from table name Group By column name have COUNT (*) >1) Order BY column name

Operation Result:

Note * Query all duplicate fields under a column in the table, and if you want to query the column for the number of repeating bars >=n, simply change the ">1" in the SQL statement to "N-1" .

2.select column Name, COUNT (*) count from table name where column name in (select Column name from table name Group By column name have COUNT (*) >1) Group By column name ORDER by C Ount ASC "

Operation Result:

Note * Query the repeating fields and quantities in a column of a table and sort them in ascending order of quantity.

3.select * FROM table name where column name in (' + field name + ') Order BY column name

Note * The table in a column under a repeating field show all (the result is to click on the "Xinzheng JuJube" entry in figure II after the name passed, as a query criteria).

SQL statement Query table repeating field and display field repeating number of bars

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.