select distinct a,b1 from (
select a,max(b) b1 from table group by a
union all
select a,min(b) b1 from table group by a)