Computing.Net > Forums > Programming > How to select Top ten using sqlplus

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to select Top ten using sqlplus

Reply to Message Icon

Name: Jenny Han
Date: July 15, 2003 at 21:56:03 Pacific
OS: LINUX
CPU/Ram: 16G
Comment:

Hi,

Now I'm wanting to retrieve the top ten data from a table using sqlplus but don't know exactly how.

It works fine if I use:
select corp_cd, sum(delq) from rcrnsas.dataworldbkbl_rdd group by corp_cd order by sum(delq) desc;

But it won't work if I add 'limit 10' or 'top 10', like the following:
select top 10 corp_cd, sum(delq) from rcrnsas.dataworldbkbl_rdd group by corp_cd order by sum(delq) desc;
or
select corp_cd, sum(delq) from rcrnsas.dataworldbkbl_rdd group by corp_cd order by sum(delq) desc limit 10;

Could anyone kindly help answer? Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: programmerPhil
Date: July 16, 2003 at 02:21:23 Pacific
Reply:

I think the 'top 10' part of the statement limits the number of records used in the filter as opposed to returning the top 10 records after the filter's been applied, so you'll be getting an ordered list of the first 10 records instead of the 'top 10' of the whole list.

You could try using your first SQL statement to store the results in a dataset (or similar) then use the 'top 10' thing on that to return the first ten records of that dataset.

Phil


0

Response Number 2
Name: WilliamRobertson
Date: July 17, 2003 at 09:35:22 Pacific
Reply:

SELECT somecol FROM
( SELECT somecol FROM sometab ORDER BY somecol )
WHERE ROWNUM = 10;

ORDER BY within an inline view requires 8i or above.

You could also look at the analytic functions e.g. RANK.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Rounding up decimals in C... VB Problem in addNew



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to select Top ten using sqlplus

How to seach *.mp3 etc using batch www.computing.net/answers/programming/how-to-seach-mp3-etc-using-batch/15950.html

How to delete Top 1 * from Access? www.computing.net/answers/programming/how-to-delete-top-1-from-access/11931.html

how to select dual processing www.computing.net/answers/programming/how-to-select-dual-processing/9899.html