FileId ParentId BatchId 1 1 1 2 1 1 3 1 1 4 2 1 5 2 1 6 2 1 7 3 1 8 3 1 9 3 1 10 4 1
FileId ParentId BatchId 1 1 1 4 2 1 7 3 1 10 4 1
select t.fileid, t.parentid, batchid from (select *, row_number() over (partition by parentid, batchid order by fileid) rno from tablename) t where rno =1
SELECT a.FileId, a.ParentId, a.BatchId FROM MyTable a JOIN (SELECT MIN(FileId) AS FileId FROM MyTable GROUP BY ParentId) b ON a.FileId=b.FileId
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)