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

139
Vistas
get records that last record binded with it have a specific value

I have this caseenter image description here

where there is 2 tables:

book for example

id || --
1  || 
2  || 
3  || 

and loan for example:

id | booId  | duration
1  | 1      | 4
2  | 1      | 6
3  | 1      | **5 (last one for book1)**
4  | 2      | 2
5  | 2      | 3
6  | 3      | 8
7  | 3      | **(5 not the last one so i don't need book3)**
8  | 3      | 6
9  | 2      |  **5 (last one for book2)**

I need to get all books id , where the last loan duration equals , so in this example it will be : [1,2]

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

One method uses aggregation:

select book_id
from loans l
group by book_id
having max(id) = max(case when duration = 5 then id end);

This checks that the last id for a given book matches the last id for a given book with the duration you want.

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