Search mysql table starting from last row

后端 未结 3 1463
轮回少年
轮回少年 2021-01-19 09:13

So, I know that there is no such thing as \"last row\" on relational databases but I couldn\'t find a better word to explain what I want to do. I have a table that looks lik

相关标签:
3条回答
  • 2021-01-19 09:49

    Just put an index on the time stamp field. Mysql will take care of it for you.

    0 讨论(0)
  • 2021-01-19 10:04

    What I want to do is a select that starts searching from the highest time field and since I know it is sorted from lowest to highest I want it to stop searching when ...

    I really don't think you can tell MySQL to stop querying after a certain condition is met.

    As a matter of fact, I really don't think you should care either. Querying is the database job and it does it pretty well. If it's a matter of performance, you should not see any difference until many centuries :)

    0 讨论(0)
  • 2021-01-19 10:09

    What you're asking for is an index. I suggest you do some research into how b-tree indexes work.

    If you had an index on the time field, the engine would essentially do what you're asking for - as the index would be ordered, it would "know" that it only needs to find the earliest point you're asking for and return everything after it.

    http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

    0 讨论(0)
提交回复
热议问题