I'm refactoring a document processing app and I think I see an opportunity to substitute a query for a lot of code. A db table contains a row for each occurrence of a dictionary term in a document. A row contains the character position in the document of the first letter of the dictionary entry and a code number that is associated with the dictionary term. For example here is a set of rows that resulted from processing a single document.

```
doc        pos        code
55          20          44
55         169          44
55         328          44
55          86         174
55          98         393
55         566         393

```

The problem is to return only the rows with the first occurrence of each code. So for this example rows one, four and five should be returned. It 'feels' like a group by code could do this but I can't figure out the condition for a group by that would select the rows with the lowest pos for each code.
A query solution needs to work only for ms sqlserver.