# How can I get all the fields and rows of the most recent write from Elastic with essql?

**URL:** <https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [June 18, 2020, 5:33am UTC](https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563 "2020-06-18T05:33:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaffarkazi](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jaffarkazi](https://discuss.elastic.co/u/jaffarkazi)\
**Post date:** [June 18, 2020, 5:33am UTC](https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563/1 "2020-06-18T05:33:07Z")

</div>

I have employee records, (say name, dob, address) and a timewritten field, which is time converted to seconds.  
This data is written to my index every 5 seconds. Suppose there are 5 records.  
Run 1 will write employee records with timewritten as 10 for example.  
Run 2, after 5 seconds, will write employee records with timewritten as 15.  
And so on.

What is the SQL I can use to get all records of the most recent (max) timewritten?  
I'm trying this on Kibana Canvas, where JOINs and IN is seemingly not supported.

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [June 18, 2020, 6:16am UTC](https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563/2 "2020-06-18T06:16:18Z")

</div>

Hey,  
You can try using the following

```auto
essql
query="SELECT ...
FROM index_1
WHERE ...
ORDER BY timestamp DESC"
| math "first(employee_unique_identifier)"
| render

```

---

<div class="post-metadata">

**Author:** ![jaffarkazi](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jaffarkazi](https://discuss.elastic.co/u/jaffarkazi)\
**Post date:** [June 18, 2020, 6:32am UTC](https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563/3 "2020-06-18T06:32:50Z")

</div>

As I said, ALL the records with all fields of that single timewritten value, not a single one. And definitely not a single field.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 16, 2020, 6:36am UTC](https://discuss.elastic.co/t/how-can-i-get-all-the-fields-and-rows-of-the-most-recent-write-from-elastic-with-essql/237563/4 "2020-07-16T06:36:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
