1

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?

enter image description here

1
  • Please don't use images Commented Apr 23 at 19:44

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.