Sort in the order the array is stored

I have a database field that holds an array of IDs, such as 3,7,2

I have a server action that performs a single database query to get the correct row in my database and return that rows array of numbers.
Inside the same server action I have a multi record database query to another table, and the condition is that the split(",") IDs returned must be IN the array.

All is well and that works perfectly, however the records are retuned in ASC order of 2,3,7 and not as they are stored with 3,7,2

To get around the problem initially I changed my server action removing the multi record query and adding a repeat instead that does the split, and feeds each number into another single database query step in the repeat.

This now returns all the results in the order they are stored.

Here is my issue I am faced with now, I need to somehow use a GroupBy to display the records in two different groupings, which I can get to work if I return to my original method but then I lose the sorting.

I need to have the array read and the number order retained as it is stored and a groupBy together, any ideas?

Community Page
Last updated: