简体   繁体   中英

Return index value of each row in MySQL

I would like to know if there is a way to return the current index of each row in a MySQL query, for example:

SELECT current_index, name FROM table LIMIT 10,10

So that the resulting rows would have

10, 'somename',
11, 'somename',
etc....

It would be a value based on the starting limit value.

SET @rn = 10;

SELECT  @rn := @rn + 1 AS current_index,
        name
FROM    mytable
LIMIT   10, 10

Please note that LIMIT 10, 10 means entries 11 to 20 .

Also note that LIMIT without a stable ORDER BY is not guaranteed to persist from query to query (and does not persist in some engines).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM