SELECT BatchNumber,MAX(Id) FROM dbo.SceneryOrder WHERE RowStatus=1 AND BatchNumber<>'' GROUP BY BatchNumber ORDER BY 2 DESC