Mysql & php: temporary / virtual identifiers for query results?

I wonder if it is possible to assign temporary / virtual identifiers for the query result?

For example, I have this as my request,

SELECT 

pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content

FROM root_pages

ORDER BY pg_created DESC

output:

ID  URL     Title   Content 
53  a       A       xxx 
40  b       B       xxx 
35  c       C       xxx  

you can see the gap between the identifiers - they are very untidy. I wonder if I can create a virtual column or something else so that I have the result below,

ID  URL     Title   Content  Virtual ID
53  a       A       xxx      3
40  b       B       xxx      2
35  c       C       xxx      1 

from a query like below

SELECT 

pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content

FROM root_pages

ORDER BY virtual_id DESC 

is it possible?

thank!

0
source share
1 answer

If you still keep the position of each line take a look at this answer

MySQL gets row position in ORDER BY

0
source

Source: https://habr.com/ru/post/1772386/


All Articles