There is such a table
Actually we need the last entry in this table with Id2 = 1 and the last entry with Id2 = 2.
The problem is that there may be 3 and 4. And they will need to be included in the sample. I do not know in advance how much Id2 will be there.
I have a cycle option on my mind. Perhaps easier?
I can not guess here.
Id - primary key identifier.
MSSQL

SELECT MAX(id), id2 FROM [table] GROUP BY id2 ORDER BY 1, no? - Yaant