If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Equal to Mysql LIMIT Clause in Db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-05, 06:57
kbmkumar kbmkumar is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Equal to Mysql LIMIT Clause in Db2

Hi,

Mysql Query : SELECT * FROM TABLE WHERE {CONDITION} LIMIT 0,10

This query will fetch the first 10 records and if i put like LIMIT 20,30 it will fetch the in between 10 records.

Can anyone help me,how can i achieve this functionality in DB2.

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 01-13-05, 09:16
Tank Tank is offline
Registered User
 
Join Date: Feb 2004
Location: Copenhagen
Posts: 220
Arrow Partly

Hi

If you append: 'fetch first xxx records only' to your SQL
statement you can limit the return set - though, to the best
of my knowlege, you cannot starrt at a certain row number.

SY
__________________
Kristian K. Hansen
Project Supervisor
National Board of Health
Reply With Quote
  #3 (permalink)  
Old 01-13-05, 09:42
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
you can start at a certain row, its not as "pretty" as mysql syntax, but here is some DB2 SQL that will achieve what you want.


WITH Viewer AS(
SELECT XX, YY, ZZ, ROW_NUMBER() OVER(ORDER BY XX DESC) AS RN
FROM MY_TABLE
FETCH FIRST 20 ROWS ONLY
)

SELECT F.XX, F.YY, F.ZZ
FROM Viewer F
WHERE RN BETWEEN 10 AND 20 ORDER BY F.XX


You might need to play with it abit, but it will work.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On