SELECT a.* FROM product_template a INNER JOIN (SELECT p_id,MAX(ID) as max_id FROM product_template where state >= 1 GROUP BY p_id DESC ) b ON a.p_id=b.p_id AND a.ID=b.max_id where a.p_id in ('207','229','46')