Re: Tricky SQL Problem: Top "n" of queried records

From: <larionov_at_yahoo.com>
Date: 1998/03/23
Message-ID: <6f6f4n$mpo$1_at_nnrp1.dejanews.com>#1/1


How about just like:

select something
from table

where rownum < 4;

In article <35168C67.5A454A63_at_ti.com>,   p-chang_at_ti.com wrote:
>
> select a.ord_col, a.other_stuff
> from table_name a
> where 3>(select count(*)
> from table_name b
> where b.ord_col < a.ord_col
> )
> order by a.ord_col;
>
> Johan Thorselius wrote:
>
> > Brenda Muller wrote:
> >
> > > In Sybase (and Sybase alone), you can "set rowcount 3" at the beginning
 of your
> > > transaction, which will restrict the server to returning only 3 rows.
 There is
> > > nothing analogous to this in Oracle.
> > >
> > > Brenda Muller
> > >
> >
> > Yes, the following should be equiv. in Oracle:
> >
> > SELECT deptno, sum(salary) FROM emp
> > GROUP BY deptno
> > ...order by something relevant....
> > WHERE ROWNUM < 4;
> >
> > But you must sort the resultset so the rows you are interested in are
 placed first.
> >
> > Best regards
> >
> > Johan Thorselius
>
>

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Mon Mar 23 1998 - 00:00:00 CET

Original text of this message