Home » RDBMS Server » Server Administration » top-N query
top-N query [message #375129] Mon, 30 July 2001 02:24 Go to next message
Norvin
Messages: 22
Registered: July 2001
Junior Member
I want to make a query and i need the top 50 row. But when i issue the following command i got an error message:

SELECT * FROM
(SELECT * FROM table1 ORDER BY field1)
WHERE rownum < 51;

ORA-00907: missing right parenthesis
(SELECT * FROM table1 ORDER BY field1)
*

was it that, i cannot make an ORDER BY statement in the FROM clause? If yes how can retrieve that top 50 row?

Our Database version is :
Oracle7 Server Release 7.3.4.0.0 - Production
PL/SQL Release 2.3.4.0.0 - Production
CORE Version 3.5.4.0.0 - Production
TNS for Intel SVR4 UNIX: Version 2.3.4.0.0 - Production
NLSRTL Version 3.2.4.0.0 - Production
Re: top-N query [message #375130 is a reply to message #375129] Mon, 30 July 2001 07:35 Go to previous messageGo to next message
Anthony
Messages: 48
Registered: September 2000
Member
The Query is correct. It works in Oracle8.1.6.
I think the problem is due to Oracle Version.
Re: top-N query [message #375132 is a reply to message #375129] Mon, 30 July 2001 07:57 Go to previous messageGo to next message
Hans
Messages: 42
Registered: September 2000
Member
because group by does implicit a sorting operation you can use sometimes as a workaround 
the <b>group by clause</b> with Oracle 7.3 - Oracle 8.0.5
 
select field1, field2, field3, .. , fieldn from
   (
   select field1, field2, field3, .. , fieldn, rowid from table
      group by field1, field2, field3, .. , fieldn, rowid
   )
where rownum < 51;
Re: top-N query [message #375143 is a reply to message #375129] Tue, 31 July 2001 03:38 Go to previous message
Amit
Messages: 166
Registered: February 1999
Senior Member
select * from table1
where rownum <= 51;
Previous Topic: how to find
Next Topic: Re: Get back SQL used to create a view?
Goto Forum:
  


Current Time: Tue Dec 24 08:11:09 CST 2024