mysql & php: temporary/ virtual ids for query results?

不羁的心 提交于 2019-12-12 01:29:20

问题


I wonder if it is possible to assign temporary/ virtual IDs for a query result?

For instance, I have this as my query,

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 the gap between the IDs - they are very untidy. I wonder if I can make a virtual column or something so that I have the output 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 this 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??

thanks!


回答1:


If you still persist on getting the position of each row take a look at this answer

MySQL get row position in ORDER BY



来源:https://stackoverflow.com/questions/4063998/mysql-php-temporary-virtual-ids-for-query-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!