I am trying to retrieve latest version of rows and following SQL works for me
select id, max(version), marketplace, package from mytable where marketplace = 'XXX' and package = 'YYY' group by marketplace, package order by version desc
But I am unable to get equivalent HQL working, e.g.
from mytable m1 where m1.version = (select max(m2.version) from mytable m2 where m2.marketplace = 'XXX' and m2.package = 'YYY' and m1.id = m2.id) group by m1.marketplace, m1.package order by m1.version desc
Though this query compiles and runs but returns wrong row. Any idea? Thanks.
|