Get The Latest values For Same ID/Duplicate ID
Try this:

SELECT primary_table.product_id, primary_table.on_hand, primary_table.created_at 
     FROM 
`table_name` primary_table, 
(SELECT MAX(purchase_id) as pId FROM `table_name` Group by product_id) second_table 
     where primary_table.purchase_id = second_table.pId