sqldatetimeselectdatatableparadox

The table has no ID, the date is contained in two columns


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


Solution

  • 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.