 <p>Try this:</p> <pre><code>;with cte as (select *, row_number() over (partition by prod_id, branch order by transaction_date desc) rn from inv_table) select * from cte where rn = 1 </code></pre> <p>The <code>row_number</code> function will group records for the same <code>prod_id</code> and <code>branch</code> combination, and then number them in descending order of the <code>transaction_date</code>. After that, the latest results for each unique combination are simply the rows corresponding to <code>rn</code> = 1.</p> <p><a href="http://rextester.com/DBGJ54661" rel="nofollow">Demo</a></p>