How to select first 50 rows?
Posted in 2003
Asker wanted a SQL statement to return only 50 rows out of 500. Replies: use SELECT FIRST 50 * FROM table (note the column list/'*' after the number), available from version 7.31 onward and confirmed working on 7.31 and 9.3. For older engines, a correlated subquery counting rows (WHERE 50 > (SELECT COUNT(*) ... )) was suggested. For paging through successive 50-row chunks, Art Kagel recommended carrying the last primary key value forward: SELECT FIRST 50 ... WHERE prim_key > ? ORDER BY prim_key.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
Hi guys, If i have a total 500 rows of records set, but i need to return 50 rows at one time by a sql statement. Do you know how to do that? Thanks in advance. Miyaki __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/
Hi,
I have done this before........
Try this:
SELECT FIRST 50 FROM <tablename>
Hope it helps.
Marius.
-----Original Message-----
From: miyaki [mailto:lcib@yahoo.com]
Sent: 29 October 2003 03:55 AM
To: ids@iiug.org
Subject: How to select first 50 rows? [2091]
Hi guys,
If i have a total 500 rows of records set, but i need
to return 50 rows at one time by a sql statement. Do
you know how to do that?
Thanks in advance.
Miyaki
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
The
FIRST n works fron 7.31 on.
In old versions you can use:
select order_num, total_price
from items a
where 50 > (
select count(*)
from items b
where b.total_price > a.total_price
)
order by 2
On Wed, 29 Oct 2003 00:10:10 -0500 (EST)
"Erasmus, Marius" <MErasmus@ejustice.pwv.gov.za> wrote:
> Hi,
>
> I have done this before........
>
> Try this:
> SELECT FIRST 50 FROM <tablename>>
> Hope it helps.
>
> Marius.
>
> -----Original Message-----
> From: miyaki [mailto:lcib@yahoo.com]
> Sent: 29 October 2003 03:55 AM
> To: ids@iiug.org
> Subject: How to select first 50 rows? [2091]
>
> Hi guys,
>
> If i have a total 500 rows of records set, but i need
> to return 50 rows at one time by a sql statement. Do
> you know how to do that?
>
> Thanks in advance.
>
> Miyaki
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
>
>
--
Mit freundlichen Grüßen
Gerd Kaluzinski
\\\\\\\\|//
(o o)
--------------------------------------------------ooO-(_)-Ooo---
Gerd Kaluzinski mailto:gerd.kaluzinski@bytec.de
Manager Consulting mailto:support@bytec.de
Informix Certified Senior System Engineer
http://www.bytec.de
BYTEC GmbH Telefon: 07541-585-1019
Hermann-Metzger-Str. 7 Fax : 07541-585-2019
88045 Friedrichshafen Ooo.
-------------------------------------------------.ooO----( )---
( ) (_/
\\\\_)
just write into a named pipe and pick up row by row! -----Ursprüngliche Nachricht----- Von: miyaki [mailto:lcib@yahoo.com] Gesendet: Mittwoch, 29. Oktober 2003 02:55 An: ids@iiug.org Betreff: How to select first 50 rows? [2091] Hi guys, If i have a total 500 rows of records set, but i need to return 50 rows at one time by a sql statement. Do you know how to do that? Thanks in advance. Miyaki __________________________________ Do you Yahoo!? Exclusive Video Premiere - Britney Spears http://launch.yahoo.com/promos/britneyspears/
Pass the primary key around (perhaps save the last key received in a cookie)
then the query can be:
select first 50 prim_key, ....
from atable
where prim_key > ?
and ....
order by prim_key;
Or if you will be ordering by another set of columns then pass them around (if
those are not unique just tack the primary key following the order by columns.
Art S. Kagel
----- Original Message -----
From: Marius Erasmus <MErasmus@ejustice.pwv.gov.za>
At: 10/29 1:03
> Hi,
>
> I have done this before........
>
> Try this:
> SELECT FIRST 50 FROM <tablename>>
> Hope it helps.
>
> Marius.
>
> -----Original Message-----
> From: miyaki [mailto:lcib@yahoo.com]
> Sent: 29 October 2003 03:55 AM
> To: ids@iiug.org
> Subject: How to select first 50 rows? [2091]
>
> Hi guys,
>
> If i have a total 500 rows of records set, but i need
> to return 50 rows at one time by a sql statement. Do
> you know how to do that?
>
> Thanks in advance.
>
> Miyaki
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
Hi,
The exact syntax on 9.3 versions for this operation is :
SELECT FIRST 50* from <tablename>
Do not forget the '*' following number 50.
Hope this helps.
miyaki <lcib@yahoo.com> wrote:
Hi guys,
If i have a total 500 rows of records set, but i need
to return 50 rows at one time by a sql statement. Do
you know how to do that?
Thanks in advance.
Miyaki
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
---------------------------------
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
Does anyone know if this works on 7.31?
Silvana
-----Original Message-----
From: Ravi T [mailto:ravit29@yahoo.com]
Sent: Wednesday, October 29, 2003 11:28 AM
To: ids@iiug.org
Subject: Re: How to select first 50 rows? [2102]
Hi,
The exact syntax on 9.3 versions for this operation is :
SELECT FIRST 50* from <tablename>
Do not forget the '*' following number 50.
Hope this helps.
miyaki <lcib@yahoo.com> wrote:
Hi guys,
If i have a total 500 rows of records set, but i need
to return 50 rows at one time by a sql statement. Do
you know how to do that?
Thanks in advance.
Miyaki
__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/
---------------------------------
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
Yes. It
works. I already needed and tested.
>From: "Meza, Silvana" <smeza@fheg.follett.com>
>To: ids@iiug.org
>Subject: RE: How to select first 50 rows? [2108] Date: Thu, 30 Oct 2003
>08:30:51 -0500 (EST)
>
>Does anyone know if this works on 7.31?
>
>
>Silvana
>-----Original Message-----
>From: Ravi T [mailto:ravit29@yahoo.com]
>Sent: Wednesday, October 29, 2003 11:28 AM
>To: ids@iiug.org
>Subject: Re: How to select first 50 rows? [2102]
>
>
>Hi,
> The exact syntax on 9.3 versions for this operation is :
>
>SELECT FIRST 50* from <tablename>>
>Do not forget the '*' following number 50.
>
>Hope this helps.
>
>miyaki <lcib@yahoo.com> wrote:
>Hi guys,
>
>If i have a total 500 rows of records set, but i need
>to return 50 rows at one time by a sql statement. Do
>you know how to do that?
>
>Thanks in advance.
>
>Miyaki
>
>__________________________________
>Do you Yahoo!?
>Exclusive Video Premiere - Britney Spears
>http://launch.yahoo.com/promos/britneyspears/
>
>
>---------------------------------
>Do you Yahoo!?
>Exclusive Video Premiere - Britney Spears
>
_________________________________________________________________
MSN Messenger: instale grátis e converse com seus amigos.
http://messenger.msn.com.br