Home » SQL & PL/SQL » SQL & PL/SQL » limiting distinct value results
limiting distinct value results [message #8734] Mon, 22 September 2003 12:24 Go to next message
DR
Messages: 12
Registered: July 2003
Junior Member
I have the following:
select distinct intst
from owner.tableone
where intst is not null;

The result values are:
4
104
204
304
404
504

For an application sample, I only want the first three values (4, 104, 204). How would I limit the output from the select?

TIA - Denise
Re: limiting distinct value results [message #8735 is a reply to message #8734] Mon, 22 September 2003 12:47 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
If you want only the first three (smallest values):

select *
  from (select distinct intst
          from owner.tableone
         where intst is not null
         order by intst)
 where rownum <= 3;


If you only want any three:

select distinct intst
  from owner.tableone
 where intst is not null
   and rownum <= 3;
Re: limiting distinct value results [message #8737 is a reply to message #8735] Mon, 22 September 2003 12:55 Go to previous message
DR
Messages: 12
Registered: July 2003
Junior Member
Thanks, Todd!
The first query is the one that I was needing. - Denise
Previous Topic: Finding tables with given field and given values
Next Topic: two phase commit
Goto Forum:
  


Current Time: Thu Apr 25 17:04:08 CDT 2024