First time jooq user here. I need to convert regular SQL statement with nested select below into jooq. Any idea if I am on the right path? I appreciate any help.
//select *
//from profile
//where (profile_id, effective_date) in (
// select profile_id, max(effective_date) as date
// from profile
// group by profile_id
// )
This is what I have but not sure if even correct:
Result<Record> profiles = dsl_
.select(PROFILE.fields())
.from(PROFILE)
.where(PROFILE.PROFILE_ID, PROFILE.EFFECTIVE_DATE) in (create
.select(PROFILE.PROFILE_ID, max(PROFILE.EFFECTIVE_DATE) as date
.from(PROFILE)
.groupBy(PROFILE.PROFILE_ID)))
.fetch();
You want to use the DSL.row()
constructor, in order to construct a row value expression predicate.
Here's how to do that with jOOQ:
// Assuming this:
import static org.jooq.impl.DSL.*;
// Write
Result<Record> profiles = dsl_
.select(PROFILE.fields())
.from(PROFILE)
.where(row(PROFILE.PROFILE_ID, PROFILE.EFFECTIVE_DATE).in(
select(PROFILE.PROFILE_ID, max(PROFILE.EFFECTIVE_DATE).as("date"))
.from(PROFILE)
.groupBy(PROFILE.PROFILE_ID)
))
.fetch();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With