Re: SQL QUERY

From: N.Prabhakar <prabhs_at_pacific.net.sg>
Date: 1996/12/05
Message-ID: <585nhg$qvp_at_newton.pacific.net.sg>#1/1


KMAQ65A_at_prodigy.com (Shivakumar Rajagopal) writes: > Lets say a table is there called account_master and it has a column
> called account_type. I need a query to display the first 10 accounts in
> each of the account types. Lets say there are about 10 account types and
> each of them has more than 100 rows.
>
> Would appreciate if you can reply on srajago774_at_aol.com
>
> Regards
>
>
> shiv
>

Hi there,

Try the following

select a.type, a.amount from t1 a
where 10 > (select count(*)

            from table2 b
            where a.type = b.type
            and   a.amount < b.amount)

If you want only 5 top rows for every type, replace 10 by 5.

I simulated your example with the above query. I think it works. Please let me know the outcome of your testing.

Regards

N.Pabhakar Received on Thu Dec 05 1996 - 00:00:00 CET

Original text of this message