SELECT * FROM ( SELECT temp.*, @rn := IF(@prev = order_id,@rn + 1,1) AS rn, @prev = 1 FROM (SELECT * FROM or_task_node ORDER BY created_date DESC) temp JOIN (SELECT @rn := 0) AS vars ) t WHERE t.rn = 1 and order_id = 101768 group by order_id;