Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2007

    Unanswered: 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?


  2. #2
    Join Date
    Jul 2006
    Pune , India
    search for
    row_number() over(order by ....)
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  3. #3
    Join Date
    Jan 2007
    Jena, Germany
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts