Dmirii Berrington
Dmirii Berrington

Reputation: 89

How to sort it in jpql?

I want to sort it in the following order: eee, ddd, then other in alphabetical order.

input:
1: aaa
2: bbb
3: ccc
4: ddd
5: eee

output:
1: eee
2: ddd
3: aaa
4: bbb
5: ccc

Upvotes: 0

Views: 24

Answers (1)

jarlh
jarlh

Reputation: 44795

Use a case expression to get 'eee' and 'ddd' first, then sort the rest alphabetically:

ORDER BY case when col = 'eee' then 1
              when col = 'ddd' then 2
              else 3
         end,
         col
              

Upvotes: 1

Related Questions