Answers for "jooq finding lastest value in table"

SQL
0

jooq finding lastest value in table

// Assuming these static imports
import static org.jooq.impl.DSL.*;
import static com.example.generated.Tables.*;

Student t = STUDENT.as("t");
Field<Date> maxDate = max(STUDENT.EVENT_DATE).as("MaxDate");
Table<?> tm = table(select(STUDENT.ID, maxDate)
                   .from(STUDENT)
                   .groupBy(STUDENT.ID)).as("tm");

ctx.select()
   .from(t)
   .join(tm)
   .on(t.ID.eq(tm.field(STUDENT.ID)))
   .and(t.EVENT_DATE.eq(tm.field(maxDate)))
   .fetch();
Posted by: Guest on October-25-2020

Code answers related to "jooq finding lastest value in table"

Code answers related to "SQL"

Browse Popular Code Answers by Language