SELECT DISTINCT TOP 2 PartId, IdNumber, Length
FROM
( SELECT PartId, IdNumber, Length, ROW_NUMBER() over(partition by IdNumber order by Length) Orden
FROM [Ayuda]
) A
WHERE A.Orden = 1
ORDER BY Length
SELECT DISTINCT TOP 2 PartId, IdNumber, Length
FROM
( SELECT PartId, IdNumber, Length, ROW_NUMBER() over(partition by IdNumber order by Length) Orden
FROM [Ayuda]
) A
WHERE A.Orden = 1
ORDER BY Length