tags:

views:

25

answers:

3

If I issue a query like this:

select c1, c2, c3
from table
group by c1;

i get distinct results for c1, but how do i sort it (e.g. c2 descending) before the group by?

+2  A: 
select c1, c2, c3 
from (select c1, c2, c3 from table order by c2 desc) t 
group by c1;
Vitalii Fedorenko
Thanks, does the job!
metafex
A: 

Your question is unclear, but if you need got higher value of c2 for each c1 you may use Max

select c1, Max(c2), Max(c3)
from table
group by c1
Michael Pakhantsov
A: 

Your query won't work as is. If I understand what you want try something closer to this:

select c1,c2,c3 from table group by c1,c2,c3 order by c1,c2 desc

Tahbaza