try thisselect ur.[User], ur.[Role]from( select ug.[User], rg.[Role], Role_Cnt, rn = row_number() over ( partition by ug.[User] order by count(*) desc, Role_Cnt ) from user_group ug inner join ( select [Role] , [Group], Role_Cnt = count(*) over ( partition by [Role] ) from role_group ) rg on ug.[Group] = rg.[Group] group by ug.[User], rg.[Role], rg.Role_Cnt) urwhere ur.rn = 1
KH[spoiler]Time is always against us[/spoiler]