Skip to content

Preserve order of results with WHERE IN with jOOQ

The issue has already been described in detail in ORDER BY the IN value list,

but to repeat: I want to select items with ids 1,3,2,4 in that specific order.

My jOOQ snippet:

The resulting results list will have items in order of 1,2,3,4. How can I preserve the order of the items with jOOQ?

Advertisement

Answer

You can use Field.sortAsc() for this:

Or, of course, to avoid repeating the list, use a local variable:

See also this article about sort indirection here.

User contributions licensed under: CC BY-SA
5 People found this is helpful