Selecting all records entered in a particular day - MySQL

前端 未结 2 624
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 19:06

I am currently working on a Mailbox for a website, holding a large number of messages within a database, where there is an option to filter the mails according to th

相关标签:
2条回答
  • 2021-01-15 19:33

    I suggest first that you maintain the records in the table sorted by date. Doing so, allows you to not need to compare every value, but you can use binary search to find the two boundaries (begin and end) of records with the desired date. I would also use the time stamp. If you store is as timesstamp and not as text, it will be number, and its very fast at doing the comparison.

    0 讨论(0)
  • 2021-01-15 19:34

    I would use method 1 and do the filtering with

    WHERE 
         your_timestamp >= search_date 
    AND 
         your_timestamp < search_date + INTERVAL 1 DAY
    

    assuming your search_date is of type DATE. MySQL can use an index in this case.

    See this fiddle. Have a look at the execution plan to verify the use of the index.

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