Re: SIMPLE SQL QUESTION.

From: <fgreene_at_hayes.com>
Date: 1 Jul 93 08:00:26 EDT
Message-ID: <7549.2c32999a_at_hayes.com>


In article <4168.1599.uupcb_at_factory.com>, jared.hecker_at_factory.com (Jared Hecker) writes:
> Is
> CV>there a way, without creating some sort of dummy field, to write a SQL
> CV>query so that instead of returning all records satisfying a where
> clause,
> CV>it returns only the first 5 records satisfying that clause.
>
> CV>Is there an easy way to do this?

In Oracle, every retrieval from the databasae also returns a dynamic variable called ROWNUM. If your query retrieves 27 records then ROWNUM will have values of 1 through 27. You can check it by a statement like

	SELECT var1, var2, var3, ROWNUM
	FROM   the_table;

In your specific case, what you need is a statement like

	SELECT var1, var2, var3
	FROM   the_table
	WHERE  ROWNUM <= 5;
Received on Thu Jul 01 1993 - 14:00:26 CEST

Original text of this message