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 > Select specific rows from a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-07, 22:14
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
Select specific rows from a table

I'm migrating my database system to DB2,
i've can't figure out how to select a specific rows in a table,
I'm retrieving data to show it page-by-page, each page requires 10 rows only,
i want to retrieve only 10 rows everytime.

For mysql,
I'll use "Select * from account LIMIT 0,10"

For mssql,
I'll use "SET ROWCOUNT=10;Select top 10"

For DB2,
I've found out the FETCH FIRST 12 ROWS ONLY staff,
but thats only getting rows start from the first,
how if i want to get rows in the middle?

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-11-07, 00:49
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
search for
row_number() over(order by ....)
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 04-11-07, 07:41
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
First of all, you will need an ordering criteria. If you don't have an ORDER BY clause (or use ORDER BY inside the ROW_NUMBER() function as Rahul has shown), then DB2 can return any arbitrary row.

Remember: Relational tables represent sets of rows, and sets are - per definition - not sorted. Thus, there is no concept like a "first row" or "second row".
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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