select * from ( select ROW_NUMBER() over(partition by ProductTypeID order by SortCode desc ) rum,* from dbo.T_ProductType_Img img where img.IsDelete='False' ) tem where rum=1