[comp.databases] SELECT only x number of items

lance@unigold.UUCP (Lance Ellinghouse) (10/18/90)

Is there a way to say 'I want to select only the first 5 items
that full-fill my criteria?' without using ESQLC? I would like
to really do it using straight SQL (BTW: I am using Ingres and
Ingres specific ways are fine also).

Thanks in advance.

+----------------------------------------------+------------------------------+
|Lance Ellinghouse                             |Any ideas on what to put here?|
|E-mail: lance@unigold.uucp                    |I have no idea... :)          |
|        lance@unigold.sr.com                  |                              |
|        unigold!lance@srhqla.sr.com           |                              |
|        hermix!unigold!lance@anes.ucla.edu    +------------------------------+
|USnail Mail: UNIGOLD, 16311 Ventura Blvd. Suite 1100, Encino, Ca, 91436      |
+-----------------------------------------------------------------------------+

broy@vaxa.weeg.uiowa.edu (Barbara Roy) (10/18/90)

In article <5@unigold.UUCP>, lance@unigold.UUCP (Lance Ellinghouse) writes...
>Is there a way to say 'I want to select only the first 5 items
>that full-fill my criteria?' without using ESQLC? I would like
>to really do it using straight SQL (BTW: I am using Ingres and
>Ingres specific ways are fine also).

Not being familiar with Ingres I can only vouch for what would work in Oracle
SQL. Perhaps Ingres can use the ROWNUM pseudo-column that Oracle uses?

Select * from table_name where rownum < 6;

Note that rownum is assigned before the rows are ordered by any ORDER BY clause.


Barbara Roy, Weeg Computing Center, University of Iowa, Iowa City, IA. 52242
Phone: 319-335-5506  
Internet: broy@vaxa.weeg.uiowa.edu     Bitnet: broyva@uiamvs
Disclaimer: My opinions are solely my own and may change daily.

prc@erbe.se (Robert Claeson) (10/19/90)

In a recent article broy@vaxa.weeg.uiowa.edu writes:

>Not being familiar with Ingres I can only vouch for what would work in Oracle
>SQL. Perhaps Ingres can use the ROWNUM pseudo-column that Oracle uses?
>
>Select * from table_name where rownum < 6;
>
>Note that rownum is assigned before the rows are ordered by any ORDER BY clause.

In Ingres, retreiving a limited number of rows is doable with,
among others, database procedures.

-- 
Robert Claeson                  |Reasonable mailers: rclaeson@erbe.se
ERBE DATA AB                    |      Dumb mailers: rclaeson%erbe.se@sunet.se
                                |  Perverse mailers: rclaeson%erbe.se@encore.com
These opinions reflect my personal views and not those of my employer.

benl@adt.SanDiego.NCR.COM (Ben.Lheureux) (10/21/90)

In article <1860@hulda.erbe.se> prc@erbe.se (Robert Claeson) writes:
>In a recent article broy@vaxa.weeg.uiowa.edu writes:

>>Perhaps Ingres can use the ROWNUM pseudo-column that Oracle uses?
>>Select * from table_name where rownum < 6;
>>Note that rownum is assigned before the rows are ordered by any 
>>ORDER BY clause.

>In Ingres, retreiving a limited number of rows is doable with,
>among others, database procedures.

Would you provide an example of how to do this with, and without 
database procedures?


Benoit.Lheureux@sandiego.NCR.COM      ####################################
Application Dev Tools, Dept 4775      #  Opinions are my own, not NCR's  #
16550 West Bernardo Drive             #    Farewell Micro C Magazine     #
San Diego, CA 92127 619/485-3578      ####################################

gordon@meaddata.com (Gordon Edwards) (10/22/90)

In article <5@unigold.UUCP>, lance@unigold.UUCP (Lance Ellinghouse) writes:
|> Is there a way to say 'I want to select only the first 5 items
|> that full-fill my criteria?' without using ESQLC? I would like
|> to really do it using straight SQL (BTW: I am using Ingres and
|> Ingres specific ways are fine also).
|> 

To my knowledge, there is no way to use "straight" SQL to perform your task.
If you have Ingres 6.3 you can probably use database procedures and 
temporary tables to perform this (your probably better off using ESQLC).

ESQLC is really the more appropriate method of handling procedural access.
SQL and the relational model really have no concept of tuple ordering or
partial solutions.  

-- Gordon     (gordon@meaddata.com)