how to find middle row of a table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sushanta123
    New Member
    • Oct 2008
    • 3

    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
  • docdiesel
    Recognized Expert Contributor
    • Aug 2007
    • 297

    #2
    Hi,

    there's a ROW_NUMBER() OVER() functionality in DB2. You could create a view containing this function, e.g.:
    Code:
    Create View
      schema.v_numbered
    as
      Select
        ROW_NUMBER() OVER() as ROWNO,
        id,and,other,columns
      From
        schema.mytable ;
    and then search for the row no. ( count(rows) DIV 2 ).

    Regards

    Doc Diesel

    Comment

    Working...