Click to See Complete Forum and Search --> : Retrieving top unique records


Semprise
02-05-2008, 06:35 PM
Say I have a table T with column N

N
--
5
2
8
3
9
6
2
12
23
9

I want to get the top 5 highest unique numbers: that is 23, 12, 9, 8, 6.

SELECT UNIQUE N
FROM T
WHERE ROWNUM <=5

Will give me 23, 12, 9 ,8. It seems to count the 9 twice. Without UNIQUE:

SELECT N
FROM T
WHERE ROWNUM <=5

I get 23, 12, 9, 9 ,8

Anyone know what I do to get the 5 values I want? I am using oracle 8i.

Semprise
02-06-2008, 12:13 PM
I think my example table/query was a poor one. I figured it out anyways.

chazzy
02-07-2008, 07:03 AM
did it work with a group by clause?

Semprise
02-07-2008, 07:39 PM
No, using group by gave the same results as using unique if I remember correctly.

I just had it select from a table T that held only unique values, no duplicates.