I save user inputs (comments) in these tables.
NEWS_COMMENTS
- id
- comment
PRODUCT_COMMENTS
- id
- comment
- product_id
I wanted to add a history feature to my website. Like;
-Someone commented on XX news.
-Someone commented on YY product.
-Someone commented on ZZ product.
You noticed the issue. I don’t save timestamps or dates, so I can’t be sure which comment comes first. It can be either the news comment or product comment.
Does MySQL has a feature to select last 24 hour inputs? For example,
NEWS_COMMENTS has 3 new entries in last 24 hours.
PRODUCT_COMMENTS has 5 new entries in last 24 hours.
The query should select these 8 entries ordering by their entry date/timestamp.
Can I do this without altering my current pages? Can you provide a query?
All you need to do is add a column with type
timestampand the optionDEFAULT CURRENT_TIMESTAMP. You probably don’t need any other modifications to your code – MySQL will do the magic to ensure that the timestamp is automatically filled in when you insert rows.Then you can get the rows from the last 24 hours with a simple query: