# Sort a Joined List using a secondary joined list as sort keys

**URL:** <https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [August 13, 2021, 4:16am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412 "2021-08-13T04:16:49Z")\
**Posts on this page:** 2\
**Page:** 3

<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:** [January 29, 2022, 5:54pm UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/41 "2022-01-29T17:54:16Z")

</div>

sure. I’ll PM you an email address.

---

<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:** [January 30, 2022, 9:44am UTC](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412/42 "2022-01-30T09:44:20Z")

</div>

The issue here turned out to be an edge case that the code column did not handle correctly.

By default, the code column will return the original list, sorted by the keys array in descending order.  
If you specify an ascending sort, this is achieved by simply reversing the array after it’s been sorted.  
The problem with that was if you had two or more keys with the same value, this would cause their original order to be reversed. So instead of coming back in sheet order, they would come back in reverse sheet order. Which was not the desired behaviour.

So the fix was a minor adjustment to the code column, to ensure that sheet order is preserved when two or more keys have the same value.

[Previous page](https://community.glideapps.com/t/sort-a-joined-list-using-a-secondary-joined-list-as-sort-keys/30412.md?page=2)
