Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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:

var results = create.select().from(ITEM).where(ITEM.ID.in(1,3,2,4)).fetchInto(Item.class);

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?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use Field.sortAsc() for this:

create.select()
      .from(ITEM)
      .where(ITEM.ID.in(1, 3, 2, 4))
      .orderBy(ITEM.ID.sortAsc(1, 3, 2, 4))
      .fetchInto(Item.class);

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

Integer[] ids = { 1, 3, 2, 4 };
create.select()
      .from(ITEM)
      .where(ITEM.ID.in(ids))
      .orderBy(ITEM.ID.sortAsc(ids))
      .fetchInto(Item.class);

See also this article about sort indirection here.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda