RE: query for top 10 sql?

  • From: Mark Richard <mrichard@xxxxxxxxxxxxxxxxx>
  • To: oracle-l@xxxxxxxxxxxxx
  • Date: Thu, 11 Mar 2004 13:07:16 +1100




Originally I thought the same but then noticed it was "query for" & "top
ten sql" - which I interpreted as a query about SQL (similar to the
Statspack type results).

As far as the SQL Server "TOP" equivalent - I have not seen such a graceful
solution in Oracle.  One approach I have seen includes using an ORDER BY in
a subquery and applying "where rownum <= 10" in the outer query - if the
inner query returns a large result set then a big sort is required.  A
second approach might be to use an analytical function like RANK() or
ROW_NUM() - but again a large sort is often required.  A third approach
relies on using index ordering (with a hint typically for force index
traversal) and "where rownum <= 10" applied on the original query - this
depends on a suitable index being available and is quite risky (for
example, if the index is dropped the query won't fail but will return a
very incorrect result without warning).




                                                                                
                                                       
                      "Nelson Flores"                                           
                                                       
                      <nflores@xxxxxxxxx        To:       
<oracle-l@xxxxxxxxxxxxx>                                                     
                      >                         cc:                             
                                                       
                      Sent by:                  Subject:  RE: query for top 10 
sql?                                                    
                      oracle-l-bounce@fr                                        
                                                       
                      eelists.org                                               
                                                       
                                                                                
                                                       
                                                                                
                                                       
                      11/03/2004 12:37                                          
                                                       
                      Please respond to                                         
                                                       
                      oracle-l                                                  
                                                       
                                                                                
                                                       
                                                                                
                                                       




I think he means an SQL query where you get the first 10 rows...
Like the "Top" Command in SQL Server's T-SQL, or using DUAL in Oracle ..
From what I know, there is no ANSI standard for this.



-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx
[mailto:oracle-l-bounce@xxxxxxxxxxxxx] On Behalf Of Mark Richard
Sent: Wednesday, March 10, 2004 5:28 PM
To: oracle-l@xxxxxxxxxxxxx
Subject: Re: query for top 10 sql?





Ryan,

"Top ten" what?  I think that's why there are different queries out
there.
It all depends on what you care about and I doubt that any specific
query
is right or wrong - just a different view or definition of "top ten".





                      "Ryan"

                      <ryan.gaffuri@cox.        To:
<oracle-l@xxxxxxxxxxxxx>

                      net>                      cc:

                      Sent by:                  Subject:  query for top
10 sql?
                      oracle-l-bounce@fr

                      eelists.org





                      11/03/2004 11:04

                      Please respond to

                      oracle-l









is there a standard query for this? Seems like people have different
standards.




<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible
for delivery of the message to such person), you may not copy or deliver
this message to anyone.
In such a case, you should destroy this message and kindly notify the
sender by reply e-mail or by telephone on (03) 9612-6999 or (61) 3
9612-6999.
Please advise immediately if you or your employer does not consent to
Internet e-mail for messages of this kind.
Opinions, conclusions and other information in this message that do not
relate to the official business of Transurban Infrastructure
Developments Limited and CityLink Melbourne Limited shall be understood
as neither given nor endorsed by them.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------





<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible for 
delivery of the message to such person), you may not copy or deliver this 
message to anyone.
In such a case, you should destroy this message and kindly notify the sender by 
reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
Please advise immediately if you or your employer does not consent to Internet 
e-mail for messages of this kind.
Opinions, conclusions and other information in this message that do not relate 
to the official business of Transurban Infrastructure Developments Limited and 
CityLink Melbourne Limited shall be understood as neither given nor endorsed by 
them.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

Other related posts: