开发者

how to order results from a table in MYSQL by the same order as when added to the table?

If I added a record yesterday and one today, how do I order the results by 'select * from table_name' by getting the entry added today first 开发者_StackOverflow中文版and then the older ones?


You'll need to timestamp and order by it, or order by a field with auto increment or similar.


If your primary key field is an auto-incremented integer, then you can do the following:

SELECT * FROM table_name ORDER BY pk_column DESC

If you're not using an auto-incremented integer for your primary key, then you'll need to do as Andre suggested and timestamp your rows.


Unless records are deleted, they are stored right in the order they were inserted. If records are deleted, new records are inserted not in a subsequent order. You then need to explicitly order by an "auto-incremented" ID field or a timestamp or something similar (if your table structure does provide any of these).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜