1

I have a MariaDB 10.2.21.

My table contains records that include a 'ChangeDate' field like this: '2019-09-18 10:57:26'.

I want to do a SELECT based on a timestamp, and get the nearest previous record to return.

This allows me to do a 'point-in-time' selection providing me with field values as they were at that moment.

I seeked StackOverflow but do no recognize a proper solution. Any hints? Thanks!

Szjoin
  • 47
  • 1
  • 6
  • See: [Why should I provide an MCRE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query) – Strawberry Nov 19 '19 at 11:31

1 Answers1

2

Try following Query

SELECT * 
  FROM my_table 
 WHERE ChangeDate < '2019-09-18 10:57:26' 
 ORDER 
    BY ChangeDate DESC 
 LIMIT 1
Strawberry
  • 33,750
  • 13
  • 40
  • 57
ascsoftw
  • 3,466
  • 2
  • 15
  • 23