Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Tricky SQL Problem: Top "n" of queried records
Hi,
I am not sure exactly what you are looking for. But by your the description what I understandard is you have one query which returns 'n' rows, now you are looking for "how to get only first 3 rows?".
Well, I would suggest for this is you can use "rownum" like -
select deptno, sum(salary)
from emp
where rownum < 4
group by rownum,deptno
order by rownum, deptno;
hope this will help you.
-Uday.
In article <6elf5h$l0c$1_at_nnrp1.dejanews.com>,
rtgraf_at_sintec.de wrote:
>
> How can I restrict the result of a SQL query to, say, the top 10 regarding
> some defined order criteria, e.g.
>
> SELECT deptno, sum(salary) FROM emp
> GROUP BY deptno
> <ONLY the top 3 w/regards to sum(salary)>;
>
> I do *not* want the client application to fetch only the first three
records,
> I want the Server to retrieve exactly these rows.
>
> I have a rather quirky solution using a multiply nested subquery (one
nesting
> level per "n" in the topic!)
>
> The problem is in fact a general one and I seem to have read a solution
> somewhere but forgot the source ;-(
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/ Now offering spam-free web-based newsreading
>
-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Tue Mar 17 1998 - 00:00:00 CST