How to obtain the total number of records (number of rows) after MySQL uses group_distinct)

Source: Internet
Author: User

MySQL _ after group_distinct _ How To Get The total number of records (number of rows) Problem: After using group or distinct, how to get the total number of records of the query results? -- Required, do not use subquery analysis: If there is no group, count. However, the usage is different. The statistical function is used in the database for group. In this case, how to obtain the total number of query result records is a problem. Feasibility Analysis: Is there any solution to this problem? If the problem is not possible, don't do it, for example, permanent motivation, 3-level score, and so on. Query results on the mysql terminal: mysql> select tag_id from labels where 1 = 1 group by tag_id; + -------- + | tag_id | + -------- + | 0 | 1 | 2 | 3 | 4 | 6 | 9 | 11 | 22 | 54 | + -------- + 10 rows in set (0.00 sec) finally, there is actually a number: 10 rows. Since there are all terminals, there should be a local storage. (I guess mysql won't query it again, because it has results.) solution: Use the found_rows function mysql> select found_rows (); + ------------ + | found_rows () | + -------------- + | 10 | + -------------- + 1 row in set (0.00 sec): Is there a problem with multithreading. In Java, a problem occurs when multiple threads share a connection. T1 queries select tag_id from labels where 1 = 1 group by tag_id; t2 queries other t1 queries select found_rows (); in this way, the query result of t2 is obtained. In the case of Hibernate and other thread pools, each thread will keep holding the current connection until the thread ends. In this case, the connection of each thread is different and there will be no conflict. However, make sure that there are other query SQL statements executed between the two statements. Others: ROW_COUNT () allows you to view the number of rows affected by the last update operation. ==== END === author fantaxy025025

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.