# How to get the last added item/record in a table?

**URL:** <https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086>\
**Category:** Ask for Help\
**Created:** [June 15, 2022, 7:47am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086 "2022-06-15T07:47:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![P\_Redjo](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@P\_Redjo](https://community.glideapps.com/u/P_Redjo)\
**Post date:** [June 15, 2022, 7:47am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/1 "2022-06-15T07:47:22Z")

</div>

If I have defined a parent table and a child table linked by a one-to-many relation, how can I get the row id of the last added child record to show in the parent table?

---

<div class="post-metadata">

**Author:** ![P\_Redjo](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@P\_Redjo](https://community.glideapps.com/u/P_Redjo)\
**Post date:** [June 15, 2022, 8:01am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/2 "2022-06-15T08:01:09Z")

</div>

Have found the way using “rollup” (parent-child relation not relevant). Thanks!

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [June 15, 2022, 12:10pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/3 "2022-06-15T12:10:39Z")

</div>

Glad you found it. Ya… single value column.

---

<div class="post-metadata">

**Author:** ![P\_Redjo](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@P\_Redjo](https://community.glideapps.com/u/P_Redjo)\
**Post date:** [June 15, 2022, 12:46pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/4 "2022-06-15T12:46:27Z")

</div>

Oh so that is what “single value” means! I was using “Rollup” actually. But thanks!

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [June 15, 2022, 1:01pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/5 "2022-06-15T13:01:00Z")

</div>

Single value \> last would bring in the last item from a table or from a relation.

---

<div class="post-metadata">

**Author:** ![P\_Redjo](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@P\_Redjo](https://community.glideapps.com/u/P_Redjo)\
**Post date:** [June 18, 2022, 9:14am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/6 "2022-06-18T09:14:02Z")

</div>

Hi,

I have another question on “Single Value”. The configuration of Get: First, Last Random, From Start, From End, does not allow the choice of a sort order. So a table may look like the following:

Row-id Date

* * *

abcd 6/18/2022  
jkmn 6/15/2022  
wxyz 6/17/2022

Get First of Date will return 6/18/2022. Get Last of Date will return 6/17/2022. There is no way to get 6/15/2022 unless I know its precise position From Start or From End. I will have to use Rollup to get 6/15/2022. But I will still not be able to get Row-id jkmn by either Single Value or Rollup.

Any suggestion? Thanks.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 18, 2022, 10:17am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/7 "2022-06-18T10:17:16Z")

</div>

So you want to find the row that contains the earliest date value, and fetch the RowID from that row, yes?

mmm, this is a tricky one. Here is one way it can be done.

- Firstly, convert all your Dates to numbers with a math column using the following formula: `Year(Date) * 10000 + Month(Date) * 100 + Day(Date)`. This will give you a number that looks like `20220615`
- Next, use a rollup column to find the minimum value in that column
- Then, create a single relation column that matches the minimum to the math column
- Finally, use a lookup column to fetch the Row ID through that relation

One thing to note is that if you have duplicate dates, then this method will always give you the first one. But I assume that’s what you want?

@mark - this a good example of where it would be useful to be able to do a min/max rollup and have it return a column value other than the one that’s being used for the rollup.

---

<div class="post-metadata">

**Author:** ![P\_Redjo](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@P\_Redjo](https://community.glideapps.com/u/P_Redjo)\
**Post date:** [June 18, 2022, 11:53am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/8 "2022-06-18T11:53:34Z")

</div>

Hi Darren, Thanks. Yes I understand your explanation. Your last paragraph is what I had in mind.

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [June 19, 2022, 4:03pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/9 "2022-06-19T16:03:05Z")

</div>

@Darren_Murphy Why wouldn’t you use the “Earliest” rollup?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 19, 2022, 4:10pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/10 "2022-06-19T16:10:40Z")

</div>

In this case, the poster didn’t want the date, they wanted the RowID that was associated with the earliest date. There is no direct way to do that, hence the 4 column solution that I offered.

But if we could do a max/min rollup and return a column value other than the one that is used for the rollup, then it would be a single column solution. If you recall a while back you asked for examples of things that weren’t easy to do with Glide computed columns, this is very similar to one the examples I gave at that time.

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [June 19, 2022, 4:44pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/11 "2022-06-19T16:44:45Z")

</div>

Thank you, I get the larger point of wanting a column associated with the min/max/earliest/latest.

What I was curious about is why use a Math column when you can do the “Earliest” rollup over the date column directly.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 19, 2022, 4:51pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/12 "2022-06-19T16:51:39Z")

</div>

Oh, right.

Yeah, you could do that. But then you’d need to use that date value to create the relation and subsequent lookup. But I’ve found that using dates to create relations can be problematic, so I tend to avoid it. I find it much safer (and more reliable) to first convert the date to either a string or integer value.

---

<div class="post-metadata">

**Author:** ![Mark](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mark/32/125_2.png) [@Mark](https://community.glideapps.com/u/Mark)\
**Post date:** [June 19, 2022, 5:43pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/13 "2022-06-19T17:43:46Z")

</div>

If it doesn’t work with the date then that’s a bug. I’d love to see a reproduction 😉

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [June 19, 2022, 10:11pm UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/14 "2022-06-19T22:11:24Z")

</div>

Ya relating a date column to another date column doesn’t always work because sometimes the dates have times and the two don’t match exactly. Much safer to convert dates to integers and relate the numbers.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [June 20, 2022, 1:25am UTC](https://community.glideapps.com/t/how-to-get-the-last-added-item-record-in-a-table/43086/15 "2022-06-20T01:25:01Z")

</div>

mmm, although I was thinking about it last night after Mark asked the question.  
In this particular case, it should work because you’re basically relating the _exact_ same value to itself. So even if it does have a time component it _should_ match, and if it doesn’t it’s a bug.

So yeah, @Mark, I don’t think I can come up with a breaking example for this specific use case.

That said, I’m still nervous about using dates for relations 🤪 😂
