Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda