Easy peasy!
As long as you also have an id in your entries table, this is the SQL query you need to run:
Code:
int updateCount = entityManager.createNativeQuery(
"update entries set c5 = 1 " +
"where id in " +
"( " +
" select id " +
" from ( " +
" select *, MAX (c3) OVER (PARTITION BY c1, c2) as max_c3 " +
" from entries " +
" ) t " +
" where t.c3 = t.max_c3 " +
") ")
.executeUpdate();
If the database does not support Windows Functions, then the query looks like this:
Code:
int updateCount = entityManager.createNativeQuery(
"update entries set c5 = 1 " +
"where id in " +
"( " +
" select e.id " +
" from entries e " +
" inner join ( " +
" select c1, c2, max(c3) as max_c3 " +
" from entries " +
" group by c1, c2 " +
" ) t " +
" on e.c1 = t.c1 and e.c2 = t.c2 and e.c3 = t.max_c3 " +
") " )
.executeUpdate();
Check out
this article for more details.