MySQL returns a specific row is the first row in the datasheet

Source: Internet
Author: User
Tags first row unique id

Originally my idea is to use PHP for the loop to execute the SQL statements more than once, but later a thought, doing so in the data is not much good, if more data, query so many times do not know how much resources to consume.


After trying to break the scalp, I finally found the solution. Use the count () function and "<=" to count the numbers. The specific ideas are as follows, first query the row data's unique ID value with the SELECT statement, and then use the

The code is as follows Copy Code
The select count (ID) from table where id<=xxx is counted.

The SQL statement is probably 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 ')

Here specifically, this table must have an ID table segment, and the last row of the value is larger than the previous row.

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.