PDA

View Full Version : Sorting/group by problem in SQL


mister_grimmy
12-11-2002, 06:36 AM
Next problem :D

I've got a table which contains a folder_id. Many of the values are duplicated as documents can be stored in the same folder so roughly speaking...

document no folder_id
12 4
42 1
23 2
65 3
78 1
90 9
12 3

I need to extract the folder_id so that I can get a list of folder_id in numerical order.

If i just selected the folder_id and sorted it (order by) then i'd get 1,1,2,3,3,4,9. Now I don't want the duplicate numbers.

I tried using a group by command which gave me
4,1,2,3,9 which is fine. How would I go about sorting this into the correct order (i.e. 1,2,3,4,9)?

Cheers for anyones help

scoutt
12-11-2002, 08:16 AM
use order by


"order by id DESC" or (ASC) if you want it the other way.

Dr. Web
12-11-2002, 10:58 AM
use group by WITH order by

group by field1, field2
order by field2

mister_grimmy
12-11-2002, 11:05 AM
Cheers, Just tried it and it worked fine.

Thanx for your help :)