I have a table in which a new record is added about once a second. The ID is missing from the table. The "Time" column shows the time in milliseconds, which is reset at the end of the day.
The "Date" column contains a date in the day-month-year format. What should I write in an SQL query to get the last added record every 1-2 seconds?
For quick direct usage, you can use this simple SQL query that sorts by both the Date
and Time
columns in descending order, since Time
resets daily.
SELECT *
FROM your_table_name
ORDER BY Date DESC, Time DESC
LIMIT 1;
If you want to automate this, you can run this query inside your code using a loop or by defining sleep(1 or 2)
intervals.