Re: Top ten?
Date: 19 Apr 93 16:48:35 GMT
Message-ID: <4372_at_ncrsoph.Sophia.NCR.COM>
In article <sd345.735213652_at_Paddington> sd345_at_city.ac.uk (Michael Collier) writes:
>Sorry if this is a FAQ.
>
>Suppose I am doing a group by query which returns lots of rows but I want the
>top ten (say).
>
>ie. select something, count(*)
> from a_table
> group by something
> order by something;
>
>I'd like the top ten something's, how do I do this?
There is a psuedo-column you can use called ROWNUM, which assignas a unique, sequential number to every row returned by a query. By putting where clause in you can return the top 10 rows
select something, count(*) from a_table ** where ROWNUM < 11 group by something order by something;
>
>Thanks in advance. Michael.
>--
>Michael Collier (Programmer) The Computer Unit,
>Email: M.P.Collier_at_uk.ac.city The City University,
>Tel: 071 477-8000 x3769 London,
>Fax: 071 477-8565 EC1V 0HB.
Cheers,
Tom
These views are my own and do not represent those of my company. No guarantee, implied or other, unless specified by law. Details on back.
Tom Donnelly | WIN: Tom.Donnelly_at_Sophia NCR Europe Group ISS | UUCP: ..ncrcom!ncrsoph!tdonnell Sophia Antipolis, Valbonne | France | TEL: 33-92 94 45 40Received on Mon Apr 19 1993 - 18:48:35 CEST