Re: Tricky SQL question

From: Tom Grenier <tom_at_sqlman.com>
Date: Wed, 21 Mar 2001 19:13:31 -0500
Message-ID: <3AB943AB.CEB04FBE_at_sqlman.com>


Can you use PL/SQL? If so, just create a block that creates a cursor with an open parameter of the news type, loop through the types and do two fetches for each loop iteration.

If you want different selections each time it is run you could do all the fetches for each cursor open loop and do some razzle dazzle with a random number to select two of them that will be different each time.

Tom

A&B wrote:

> I need to create a sql statement that select a specific number of records
> from a table for each unique value within a column.
>
> For example.... I have a table that stores news articles. Every news
> article has a type( headlines, health, comics, etc ). I need to select two
> news articles from the table for every news type. If there are 10 unique
> news types in the table, then I need to select two records for every type in
> the table.
>
> We tried using UNION but there are over 200 types and the sql statement was
> greater than 4000 characters!
>
> If anyone can help, I would appreciate it.
>
> The contents of this message express only the sender's opinion.
> This message does not necessarily reflect the policy or views of
> my employer, Merck & Co., Inc. All responsibility for the statements
> made in this Usenet posting resides solely and completely with the
> sender.
Received on Thu Mar 22 2001 - 01:13:31 CET

Original text of this message