Unix Technical Forum

Row Number or subset of select.

This is a discussion on Row Number or subset of select. within the DB2 forums, part of the Database Server Software category; --> Is it possible to retrive only part of query result? Like Oracle has, for example, rownum and it can ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 05:05 PM
Alex Kizub
 
Posts: n/a
Default Row Number or subset of select.

Is it possible to retrive only part of query result?

Like Oracle has, for example, rownum and it can be part of conditions:
select * from table where rownum < 10

Problem is that table is huge (billions records) and when user is
subborn enough and reach page #100,000 then application has to read and
skip these 100,000,000 records to obtaine next page.

Please, don't tell me that table can be changed, sorted and so on.
I'm talking about one particular request in one time. But I need rows
from N to N+10 from table with M rows.

Is it possible in DB2 (Version 7)?
Alex Kizub.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 05:05 PM
Mark A
 
Posts: n/a
Default Re: Row Number or subset of select.

"Alex Kizub" <akizub@yahoo.com> wrote in message
news:402AAF8B.34DCD873@yahoo.com...
> Is it possible to retrive only part of query result?
>
> Like Oracle has, for example, rownum and it can be part of conditions:
> select * from table where rownum < 10
>
> Problem is that table is huge (billions records) and when user is
> subborn enough and reach page #100,000 then application has to read and
> skip these 100,000,000 records to obtaine next page.
>
> Please, don't tell me that table can be changed, sorted and so on.
> I'm talking about one particular request in one time. But I need rows
> from N to N+10 from table with M rows.
>
> Is it possible in DB2 (Version 7)?
> Alex Kizub.
>

If you just need the first 10 rows, you can use the following on the end of
your select
FETCH FIRST 10 ROWS ONLY
See the SQL reference.

If you want some other range of rows (in the middle of the answer set), then
look at the OLAP functions with row_number () over


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 05:05 PM
Alex Kizub
 
Posts: n/a
Default Re: Row Number or subset of select.



Mark A wrote:

> "Alex Kizub" <akizub@yahoo.com> wrote in message
> news:402AAF8B.34DCD873@yahoo.com...


> If you just need the first 10 rows, you can use the following on the end of
> your select
> FETCH FIRST 10 ROWS ONLY
> See the SQL reference.
>
> If you want some other range of rows (in the middle of the answer set), then
> look at the OLAP functions with row_number () over


Mark: Thanks a lot. I'm really happy! Before our DBAs told me that this
impossible
But I still have a little problem. It doesn't work:
For SQL
select a,b,c from t order by a
I have the result.
A little modification to
select row_number() over (order by a), a,b,c from t order by a
returns me this:
SQL0104N An unexpected token "(" was found following "". Expected tokens may
include: ", FROM INTO ". SQLSTATE=42601

and this
select a,b,c from t where row_number() over (order by a) < 10 order by a
returns this:

SQL0104N An unexpected token "OVER" was found following "". Expected tokens may
include: "< > = <> <= !< !> != >= ¬< ¬> ¬= IN NOT ". SQLSTATE=42601

I played a bit during all these hours. Have no clue.
Can you help me again, please?

Alex.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 05:05 PM
Blair Adamache
 
Posts: n/a
Default Re: Row Number or subset of select.

What operating system are you on? This is definitely valid syntax for v7
on Linux/Windows/Unix (sample database):

select row_number() over (order by lastname), lastname,salary from
employee order by lastname

Alex Kizub wrote:

>
> Mark A wrote:
>
>
>>"Alex Kizub" <akizub@yahoo.com> wrote in message
>>news:402AAF8B.34DCD873@yahoo.com...

>
>
>>If you just need the first 10 rows, you can use the following on the end of
>>your select
>>FETCH FIRST 10 ROWS ONLY
>>See the SQL reference.
>>
>>If you want some other range of rows (in the middle of the answer set), then
>>look at the OLAP functions with row_number () over

>
>
> Mark: Thanks a lot. I'm really happy! Before our DBAs told me that this
> impossible
> But I still have a little problem. It doesn't work:
> For SQL
> select a,b,c from t order by a
> I have the result.
> A little modification to
> select row_number() over (order by a), a,b,c from t order by a
> returns me this:
> SQL0104N An unexpected token "(" was found following "". Expected tokens may
> include: ", FROM INTO ". SQLSTATE=42601
>
> and this
> select a,b,c from t where row_number() over (order by a) < 10 order by a
> returns this:
>
> SQL0104N An unexpected token "OVER" was found following "". Expected tokens may
> include: "< > = <> <= !< !> != >= ¬< ¬> ¬= IN NOT ". SQLSTATE=42601
>
> I played a bit during all these hours. Have no clue.
> Can you help me again, please?
>
> Alex.
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 05:05 PM
Alex Kizub
 
Posts: n/a
Default Re: Row Number or subset of select.

Of course it's valid sysnax because I took it from documentation. And it has only
this one
Actually this is JDBC on Windows XP which uses DB2 Connect Client (app driver) to
connect to
DB2 Connect Server on Linux on mainframe which connect to real DB2 on mainframe.
I don't know shorter way And that's only DV2 part of whole huge chain.

Good enough for regualar SQL. but very, very slow for billions of records.
That why I try, without success, this row_number function.

Alex Kizub.

Blair Adamache wrote:

> What operating system are you on? This is definitely valid syntax for v7
> on Linux/Windows/Unix (sample database):
>
> select row_number() over (order by lastname), lastname,salary from
> employee order by lastname
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-26-2008, 05:05 PM
Mark A
 
Posts: n/a
Default Re: Row Number or subset of select.

"Alex Kizub" <akizub@yahoo.com> wrote in message
news:402B6AE6.6133F68D@yahoo.com...
> Of course it's valid sysnax because I took it from documentation. And it

has only
> this one
> Actually this is JDBC on Windows XP which uses DB2 Connect Client (app

driver) to
> connect to
> DB2 Connect Server on Linux on mainframe which connect to real DB2 on

mainframe.
> I don't know shorter way And that's only DV2 part of whole huge chain.
>
> Good enough for regualar SQL. but very, very slow for billions of records.
> That why I try, without success, this row_number function.
>
> Alex Kizub.


The row_number() over function will not be supported until V8 of DB2 for
z/OS (which replaces OS/390). The platform where you start from (XP) or the
DB2 Connect Server server (Linux) is irrelevant. You need an SQL manual for
DB2 mainframe.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-26-2008, 05:05 PM
Alex Kizub
 
Posts: n/a
Default Re: Row Number or subset of select.

Blair Adamache <badamache@2muchspam.yahoo.com> wrote in message news:<c0et96$jpa$1@hanover.torolab.ibm.com>...
Problem does persist on mainframe DB2 (V7).

> What operating system are you on? This is definitely valid syntax for v7
> on Linux/Windows/Unix (sample database):
>
> select row_number() over (order by lastname), lastname,salary from
> employee order by lastname
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-26-2008, 05:06 PM
Mark A
 
Posts: n/a
Default Re: Row Number or subset of select.

> Problem does persist on mainframe DB2 (V7).
>

Not supported on that platform until version 8.


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 09:02 AM.


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