with tmp as ( select *,ROW_NUMBER() OVER (PARTITION BY name ORDER BY level1,level2) as num from table ) select * from tmp where num=1

with tmp as ( select *,ROW_NUMBER() OVER (PARTITION BY name ORDER BY level1,level2) as num from table ) select * from tmp where num=1