# Numerically order a local db column

**URL:** <https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011>\
**Category:** Questions about Thunkable X\
**Created:** [July 30, 2024, 11:05am UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011 "2024-07-30T11:05:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [July 30, 2024, 11:05am UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/1 "2024-07-30T11:05:58Z")

</div>

Hi all,

Has anyone got examples of numerically ordering local db’s?

I am trying to create a leaderboard from local db entries. One column in the local db is ‘time’ I want to order all the entries so smallest time first and longest last, so it can then be displayed in a DVL.

Has anyone done this? Seems simple but struggling to get it done

---

<div class="post-metadata">

**Author:** ![brianl](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@brianl](https://community.thunkable.com/u/brianl)\
**Post date:** [July 30, 2024, 5:18pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/2 "2024-07-30T17:18:15Z")

</div>

There are no blocks at the moment that do the ordering/sorting for you, but I can help provide the logic to get this working.

You would need two data tables, one that will be connected to the DVL and one that won’t. I will call the table connected to the DVL the “DVL table” and the one that isn’t just “table”. When you want to sort, empty the table. Then you can loop through the table to find the smallest ‘time’ and then add it to the table. Repeat until everything is added in.

Then you remove everything from your DVL table, loop through the table, and add row by row from the table to your DVL table.

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [July 30, 2024, 6:03pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/3 "2024-07-30T18:03:27Z")

</div>

assuming your column time is a number, and assuming you have less than 1000 rows in the table, go over this column and build a list where each entry is computed from (value of time from the current row ) \* 1000 + row\_number so you may end with a list like [42423001, 54545002, 92442003, …85345026, 13748027] - simply sort this list and it’s now in time order. As you process this list, get the remainder of each entry after dividing by 1000 - that is the row number you want to obtain in order to populate your list.  
(this is not tested)

---

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [July 31, 2024, 9:41am UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/4 "2024-07-31T09:41:06Z")

</div>

@brianl would you mind providing some blocks to follow please. Tried emulating your logic but I’m struggling to follow.

---

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [July 31, 2024, 10:33am UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/5 "2024-07-31T10:33:19Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/6/56ecd518fdaa717d56d2560aa248d5659899440b.png)  
This is the setup I have right now

---

<div class="post-metadata">

**Author:** ![brianl](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@brianl](https://community.thunkable.com/u/brianl)\
**Post date:** [July 31, 2024, 9:32pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/6 "2024-07-31T21:32:01Z")

</div>

This is slightly different than what I would do but this method works too. There are a few minor changes you will have to make.

You would have to make is to a “while app variable timelist is not empty list” after deleting all rows. Then after after the loop and before the end of the while loop, set i to 1 again.

Create another variable(let’s call it j) that will be set at 1. In “in list app variable timelist get i”, instead ‘i’, use ‘j’. Then where you have “in list app variable timelist remove i”, change ‘i’ to ‘j’, and increment j by 1.

---

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [July 31, 2024, 10:03pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/7 "2024-07-31T22:03:15Z")

</div>

Ok I will try give that a go

@brianl would you be able to provide a block example. Sometimes it’s hard to follow a text explanation

---

<div class="post-metadata">

**Author:** ![brianl](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@brianl](https://community.thunkable.com/u/brianl)\
**Post date:** [July 31, 2024, 10:28pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/8 "2024-07-31T22:28:05Z")

</div>

Unfortunately, I won’t be able to at this moment.

---

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [August 2, 2024, 7:25am UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/9 "2024-08-02T07:25:30Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/6/c6ad6cfd704be54647f597ee2450737b22fbe2e8.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/0/d0a6047b4df25f13f93b1dd38f9b4ef7c281ceaf.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/6/1650f79f6f5084c6085678f9fe56f72c212f2154.png)

@brianl do you know why when the blocks above are run, the whole db is not added to the DVL? After one button press it seems to add the first 5 entries rather than run through the whole db.

---

<div class="post-metadata">

**Author:** ![brianl](https://avatars.discourse-cdn.com/v4/letter/b/f14d63/32.png) [@brianl](https://community.thunkable.com/u/brianl)\
**Post date:** [August 6, 2024, 7:05pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/10 "2024-08-06T19:05:12Z")

</div>

In the block where you have “count with i from 1 to length of”, it should be “list of values” of your db rather than the variable “app variables timelist”

---

<div class="post-metadata">

**Author:** ![nuuzonessqnzvv](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nuuzonessqnzvv](https://community.thunkable.com/u/nuuzonessqnzvv)\
**Post date:** [August 6, 2024, 9:38pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/11 "2024-08-06T21:38:29Z")

</div>

Hi @brianl

The variable is a list so using length of the variable seemed to work ok.

When I’m in front on my computer I’ll upload the final block setup that I used to solve the issue.

Thank you for you help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [November 4, 2024, 9:38pm UTC](https://community.thunkable.com/t/numerically-order-a-local-db-column/3119011/12 "2024-11-04T21:38:44Z")

</div>

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