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

From: Steve Phelan <stevep_at_XXnospamXX.toneline.demon.co.uk>
Date: 1998/03/17
Message-ID: <890157179.4932.0.nnrp-08.c2de712e_at_news.demon.co.uk>#1/1


rtgraf_at_sintec.de wrote in message <6elf5h$l0c$1_at_nnrp1.dejanews.com>...
>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.

Then call a stored procedure that uses an explicit cursor (easiest as a 'cursor for loop') and just return the first 3 three rows. It's up to you how many rows you 'fetch', so just exit the loop after 3 fetches.

Steve Phelan. Received on Tue Mar 17 1998 - 00:00:00 CET

Original text of this message