SELECT CatsMMV.CategoryId, CatsMMV.MinV, CatsMMV.MaxV, MinI.ItemId AS MinItemID, MaxI.ItemId AS MaxItemID
FROM (SELECT CategoryId, MIN(ItemValue) AS MinV, MAX(ItemValue) AS MaxV
FROM Items
GROUP BY CategoryId) AS CatsMMV LEFT OUTER JOIN
Items AS MaxI ON CatsMMV.CategoryId = MaxI.CategoryId AND CatsMMV.MaxV = MaxI.ItemValue LEFT OUTER JOIN
Items AS MinI ON CatsMMV.CategoryId = MinI.CategoryId AND CatsMMV.MinV = MinI.ItemValue