• Your desired output seems to suggest that what you're looking for is the minimum GroupID for each item.

    Select MIN(GroupId) as GroupId, ItemId, ItemName

    From #Data

    Group by ItemId, ItemName

    Order by ItemId;