If i understand your question correctly I believe this will give you the result you want:
SELECT
[CommonName],
[Note],
[SAP],
[Timestamp]
FROM (
SELECT
[CommonName],
[Note],
[SAP],
[Timestamp],
ROW_NUMBER() OVER (PARTITION BY [SAP] ORDER BY [Timestamp] DESC) AS RN
FROM [MachineComentTracker]
WHERE [Parent] = :myParent
) D
WHERE [RN] = 1
Using ROW_NUMBER in an inner query to partition by the column SAP, which based on your explanation, seems like it's L01, L02, ..., L07? Then ordering by the column Timestamp
In the outer query, we're selecting RN = 1 to get the first entry for each partition in the inner query.
You should be able to cross apply on the same table, just like you could do a self JOIN:
Anyway, the row_number() solution is pretty classic and straightforward so I'd probably try that one first and maybe check out this one if that one ends up running too slow for your data.
I had no idea TOP 1 WITH TIES existed... this is really sweet!! No longer do I have to wrap my query just to get the most recent record for a partition.