0

I have a table that looks something like the following:

loc temp timestamp
xyz 22.4 2021-03-03T16:51:56.915000Z
xyz 21.4 2021-03-03T16:51:56.915000Z
abc 22.4 2021-03-03T17:05:38.238413Z
abc 21.4 2021-03-03T17:05:38.238478Z

What query do I need to get the most recent record back?

funnymay
  • 341
  • 1
  • 6

1 Answers1

1

There are two simple ways of getting the most recent values here, firstly, you can limit to the most recent row:

SELECT * FROM my_table LIMIT -1;

But what might be more useful in this case is to use LATEST BY:

SELECT * from my_table LATEST BY loc;

This would return the most recent rows per unique value in the loc column:

loc temp timestamp
xyz 21.4 2021-03-03T16:51:56.915000Z
abc 21.4 2021-03-03T17:05:38.238478Z

Edit: More information, along with examples can be found on the LATEST BY documentation

Brian Smith
  • 1,222
  • 7
  • 17