Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 8th, 2008, 05:02 AM
Newbie
 
Join Date: Oct 2008
Age: 23
Posts: 3
Default how to find middle row of a table?

Hi Every1,

Actually i want to retrieve the middle row(record) of a table, but i am not able to write any query to get the same..

Also i am not sure whether any function as Rownum in ORACLE that exists in DB2 or not!! If yes then can any one explain in details...

Cheers..
Thanks in advance

Sushanta
Reply
  #2  
Old October 10th, 2008, 12:24 PM
docdiesel's Avatar
Moderator
 
Join Date: Aug 2007
Location: Munich
Posts: 284
Default

Hi,

there's a ROW_NUMBER() OVER() functionality in DB2. You could create a view containing this function, e.g.:
Expand|Select|Wrap|Line Numbers
  1. Create View
  2.   schema.v_numbered
  3. as
  4.   Select
  5.     ROW_NUMBER() OVER() as ROWNO,
  6.     id,and,other,columns
  7.   From
  8.     schema.mytable ;
and then search for the row no. ( count(rows) DIV 2 ).

Regards

Doc Diesel
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles