dbTalk Databases Forums  

Re: limiting rows returned in a sql select

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Re: limiting rows returned in a sql select in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: limiting rows returned in a sql select - 08-20-2003 , 01:25 PM






ceprnatwork (AT) hotmail (DOT) com (the dragon) wrote in message news:<6e59cc25.0308200651.6edb0e2 (AT) posting (DOT) google.com>...
Quote:
I am using db2 v7.x. Command center on my PC, odbc to a database on
the MF. I have a simple select, select * from ps_ledger_adb_mtd, and
I only want to see the first 10 rows, not all 5200 plus rows. I tried
using this, select * from ps_ledger_adb_mtd fetch first 10 rows only,
and got this error message: SQL0199N The use of the reserved word
"FETCH" following "" is not valid.

Expected tokens may include: "FOR WITH ORDER UNION EXCEPT QUERYNO
OPTIMIZE ".

SQLSTATE=42601
I dont know why "fetch first ...", doesnt work, but you could try something like:

select * from (
select x.*, rownumber() over () as rn from ps_ledger_adb_mtd x
) where rn < 10

this is not as compact as "fetch first ..." but is more powerfull since you can do:

select * from (
select x.*, rownumber() over () as rn from ps_ledger_adb_mtd x
) where rn between 10000 and 10010



[...]

HTH
/Lennart
--
the above email no longer works due to spam.
values'lennart'||CHR(46)||'jonsson'||CHR(64)||'enl ight'||CHR(46)||'net'


Reply With Quote
  #2  
Old   
the dragon
 
Posts: n/a

Default Re: limiting rows returned in a sql select - 08-25-2003 , 05:03 PM






here's what I get:


------------------------------ Command Entered ------------------------------
select * from (
select x.*, rownumber() over () as rn from ps_ledger_adb_mtd x
) where rn < 10
;
-----------------------------------------------------------------------------
SQL0104N An unexpected token "(" was found following "". Expected tokens may

include: ", FROM INTO ". SQLSTATE=42601

Reply With Quote
  #3  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: limiting rows returned in a sql select - 08-25-2003 , 10:41 PM



ceprnatwork (AT) hotmail (DOT) com (the dragon) wrote in message news:<6e59cc25.0308251403.3d92bf33 (AT) posting (DOT) google.com>...
Quote:
here's what I get:


------------------------------ Command Entered ------------------------------
select * from (
select x.*, rownumber() over () as rn from ps_ledger_adb_mtd x
) where rn < 10
;
-----------------------------------------------------------------------------
SQL0104N An unexpected token "(" was found following "". Expected tokens may

include: ", FROM INTO ". SQLSTATE=42601

Sorry, you will have to name your "table" as in:

select * from (
select x.*, rownumber() over () as rn from ps_ledger_adb_mtd x
) Y where rn < 10

Lets hope it works now, I dont have the chance of trying


/Lennart


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.