•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 391,705 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,241 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser:
Views: 1758 | Replies: 4 | Solved
![]() |
Got the soln, as below
Thanks.
sql Syntax (Toggle Plain Text)
SELECT * FROM (SELECT a FROM <tbl> ORDER BY a DESC) WHERE rownum<=5;
Thanks.
Last edited by peter_budo : Jul 13th, 2008 at 3:44 am. Reason: Keep It Organized - please use [code] tags
Learn to appreciate and appreciate to learn.
•
•
Join Date: Jun 2008
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
sql Syntax (Toggle Plain Text)
SELECT * FROM <tab> WHERE rownum <=5 ORDER BY <a> DESC.
I dont think extra subquery is needed here.
pls correct me if m wrong.
Last edited by peter_budo : Jul 13th, 2008 at 3:45 am. Reason: Keep It Organized - please use [code] tags
Yes buddy, the extra sub querry is needed, as in below case :
the first 5 rown are getting sorted and then ordered, which would not essesntaily return max 5 values.
However if we use it as :
the results are first ordered in desceding order i.e max to lowest and on selecting the frist 5 rows, we get the 5 max values.
sql Syntax (Toggle Plain Text)
SELECT * FROM <tab> WHERE rownum <=5 ORDER BY <a> DESC
the first 5 rown are getting sorted and then ordered, which would not essesntaily return max 5 values.
However if we use it as :
sql Syntax (Toggle Plain Text)
SELECT * FROM (SELECT a FROM <tbl> ORDER BY a DESC) WHERE rownum<=5;
the results are first ordered in desceding order i.e max to lowest and on selecting the frist 5 rows, we get the 5 max values.
Last edited by peter_budo : Jul 13th, 2008 at 3:44 am. Reason: Keep It Organized - please use [code] tags
Learn to appreciate and appreciate to learn.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Oracle Marketplace
- Help with SQL date evaluation (Oracle)
- query get upcoming birthdays (PHP)
- retrieving a particular value with a sql query (PHP)
- php table help (PHP)
- PHP/SQL query help (PHP)
- using asp array to store db information (ASP)
Other Threads in the Oracle Forum
- Previous Thread: Accessing Oracle 9i thru Java
- Next Thread: DB Design Issues


Linear Mode