The number of rows in the data table returned by Mysql.

Source: Internet
Author: User

I have been using PHP for a project over the past few days. The project involves MySQL operations. When optimizing the query statement, we encountered the following problem: how to return several rows of data in a table.

My initial idea was to use the php for loop to execute SQL statements multiple times. But then I thought it would be nice to do this when there is not much data. If there is more data, I don't know how much resources will be consumed when I query these times.

 
After trying to break your head, I finally found a solution. Use the count () function and "<=" to calculate the number. The specific idea is as follows. First, use the select statement to query the unique id value of the row of data, and then use

The Code is as follows: Copy code
Select count (id) from table where id <= xxx.

The SQL statement is like this:

SQL code

The Code is as follows: Copy code

Select count (id) from table where id <= (select id from table where name = 'ku _ Andrew ')

The table must have an id table segment, and the value of the next row is greater than that of the previous row.

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.