-- 1 Group by groupcol, -- 2 Sort by sortcol -- 3 Add numeration for every group select table.*, row_number() over (partition by table.groupcol order by sortcol) as rm -- set number for each group from table; -- leave only one row for each group select * from (select table.*, row_number() over (partition by table.groupcol order by sortcol) as rm -- set number for each group from table) where rm = 1;