Re: Limiting # of hits via SQL

From: Martin Smith <Mikes_at_cpcug.org>
Date: 1995/07/01
Message-ID: <3t3m89$7k3_at_news1.digex.net>#1/1


That's great, but how about if you want the top 10 salaries in each DEPARTMENT?.

PS--I read that some front-ends seem of offer to do "top-x" reports "automatically." Wonder if they are using this same logic.

Martin Smith
USITC mikemad_at_asymetrix.com (Mike Madland) wrote:

> >Cheers Pete.
>
> This will only work if you are not sorting the result. If you use
> ORDER BY then rownum is useless. If you want to get a
> top 10, try (as scott/tiger):
>
> select ename, sal
> from emp
> where -sal in
> (select -sal
> from emp)
> and rownum < 11
> /
>
> The subquery does the sorting for you.
>
> Mike Madland
> mikemad_at_asymetrix.com
>
Received on Sat Jul 01 1995 - 00:00:00 CEST

Original text of this message