Unix Technical Forum

restrict the amount of a select's result set

This is a discussion on restrict the amount of a select's result set within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi, is it possible to restrict a select (with group) that it returns only the first 10 records of ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 11:56 AM
Norbert Winkler
 
Posts: n/a
Default restrict the amount of a select's result set

Hi,

is it possible to restrict a select (with group) that it returns only the
first 10 records of the result set (counted "after" group by).

--
Norbert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 11:56 AM
Charles Hooper
 
Posts: n/a
Default Re: restrict the amount of a select's result set

Norbert Winkler wrote:
> Hi,
>
> is it possible to restrict a select (with group) that it returns only the
> first 10 records of the result set (counted "after" group by).
>
> --
> Norbert


It helps to post an example of the problem that you are working with,
including all SQL statements and the expected output.

For example:
The setup:
CREATE TABLE TABLE1 (X NUMBER(10), Y NUMBER(10), Z NUMBER(10));

INSERT INTO TABLE1 VALUES (1,1,5);
INSERT INTO TABLE1 VALUES (1,3,5);
INSERT INTO TABLE1 VALUES (2,6,1);
INSERT INTO TABLE1 VALUES (5,9,8);

The SQL statement, but I only want to retrieve the first two rows:
SELECT
X,
MIN(Y) Y,
MIN(Z) Z
FROM
TABLE1
GROUP BY
X;

X Y Z
========== ==========
1 1 5
2 6 1
5 9 8

If I slide the above into an inline view, I can use ROWNUM to retrieve
only the first two rows:
SELECT
X,
Y,
Z
FROM
(SELECT
X,
MIN(Y) Y,
MIN(Z) Z
FROM
TABLE1
GROUP BY
X)
WHERE
ROWNUM<=2;

X Y Z
========== ==========
1 1 5
2 6 1

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 11:56 AM
Norbert Winkler
 
Posts: n/a
Default Re: restrict the amount of a select's result set

Am 12 Dec 2006 03:56:39 -0800 schrieb Charles Hooper:

> If I slide the above into an inline view, I can use ROWNUM to retrieve
> only the first two rows:
> SELECT
> X,
> Y,
> Z
> FROM
> (SELECT
> X,
> MIN(Y) Y,
> MIN(Z) Z
> FROM
> TABLE1
> GROUP BY
> X)
> WHERE
> ROWNUM<=2;
>
> X Y Z
> ========== ==========
> 1 1 5
> 2 6 1
>


Thanks, that solves exactly the problem.

--
Norbert
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:16 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com