473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.

Nov 12 '05 #1
7 19328
"Alex Kizub" <ak****@yahoo.com> wrote in message
news:40***************@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
Nov 12 '05 #2


Mark A wrote:
"Alex Kizub" <ak****@yahoo.com> wrote in message
news:40***************@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.

Nov 12 '05 #3
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" <ak****@yahoo.com> wrote in message
news:40***************@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.


Nov 12 '05 #4
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


Nov 12 '05 #5
"Alex Kizub" <ak****@yahoo.com> wrote in message
news:40***************@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.
Nov 12 '05 #6
Blair Adamache <ba*******@2muchspam.yahoo.com> wrote in message news:<c0**********@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

Nov 12 '05 #7
> Problem does persist on mainframe DB2 (V7).

Not supported on that platform until version 8.
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
4
by: Chris Tremblay | last post by:
I am trying to figure out how to go about retrieving the number of results returned from my queries in SQL server from VB.NET without using a the Select Count(*) query. The method that I was using...
19
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. ...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
6
by: sachin | last post by:
Hi, I am facing some strange issue in DB2 UDB 9.5.1 I have created a database on DPF implemented environment and I tried to execute following commands Db2 create table test ( name char(10)...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.