Question : jooq finding lastest value in table
Answered by : stormy-salamander-9xyp1i53ea9m
// 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();
Source : https://stackoverflow.com/questions/54484208/jooq-code-to-select-rows-which-has-latest-timestamp-from-table | Last Update : Sun, 01 Nov 20