title: How to select latest record in group using JPQL in Spring JpaRepository?
body: <p>In a SpringBoot Microservice, I am trying to select the latest record for an actor for each mean_of_payment_id. To achieve this, selecting actor content for actor_id where created_date is equaled to the subset of the nested query of max(created_date) using group by clause on mean_of_payment_id. I am using JPQL. Below are the table structure and query.</p>
  
  <p><a href="https://i.stack.imgur.com/dhWiI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dhWiI.png" alt="enter image description here"></a></p>
  
  <pre><code>    @Query("select ac from ActorContent ac "
          + "where (ac.actor.uuid=:actorUuid ) and "
          + "ac.createdDate IN ( SELECT MAX(aci.createdDate) "
              + "FROM ActorContent aci WHERE ac.actor.uuid=aci.actor.uuid "
              + "and aci.uuid = ac.uuid group by ac.meanOfPayment.id)"
          )
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/6ZPDc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6ZPDc.png" alt="enter image description here"></a></p>
  
  <p>Unfortunately, After executing the query I am getting all the records but what I am expecting is the top three rows. MeanOfPayment and Actor are the referential tables for ActorContent.</p>