Hi @shalabh.negi,
Check this out for more simple approach Query for latest records of a given set of users