Hi, Mycroft's solution is elegant and I like the way he presents the solution. However, there are a few more ways which will accomplish the task, though again I like Mycroft's solution
declare @t table(docvalue varchar(50),priority int)
insert into @t select 'aaa',0 union all select 'xxx', 1 union all select 'bbb', 3 union all
select 'ccc',0 union all select 'aaa',2
Query1:
select docvalue,priority from @t where priority <> 0 group by priority,docvalue
union all
select * from @t where priority = 0
Query 2:
select distinct * from @t where priority <> 0 group by priority,docvalue
union
select * from @t where priority = 0
Output:
docvalue priority
xxx 1
aaa 2
bbb 3
aaa 0
ccc 0
Niladri Biswas