Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    4

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

  2. #2
    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

  3. #3
    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.

Posting Permissions

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