Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32

    Unanswered: the N first records

    Is there any reserved word to obtain the N first records from a Select?

  2. #2
    Join Date
    Apr 2002
    Posts
    18
    Select * from your_table fetch first 10 rows only

    would bring you back the first 10 for instance

  3. #3
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32
    I think in an 'ordinary' select the fetch statement doesn't work.

  4. #4
    Join Date
    Apr 2002
    Posts
    18
    A select can only return 0 or 1 rows else you will receive -811 return code in a program. I thought you were talking about using a CURSOR.

    You can enter the statement at the command prompt without having to declare a cursor.


    What you need to do is declare a cursor.

    Declare Cursor CSR1
    Select * from my_table
    fetch first 5 rows only

    Please let me know if you need any more help.

  5. #5
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32
    I'm not working with any PL programs nor stored procedures, etc. In a simple query that I execute via ODBC from a client program I can't use any fetch (am I mistaken?). In other words, the sintax of a Select statement don't allow to restrict the number of returned rows.
    Thanks a lot for your help.

  6. #6
    Join Date
    Dec 2001
    Location
    Barcelona
    Posts
    32

    top N records

    hi Greg,
    I think your first response is the correct one:
    Select * from your_table fetch first 10 rows only
    But this sintax is only allowed at the last IBM version (5.1) and is not my case.
    Thanks for your help

  7. #7
    Join Date
    Apr 2002
    Posts
    18
    It mightbe helpful to post your query. However try the following.

    http://www.tek-tips.com/faqs.cfm?spi...TOKEN=32229561

  8. #8
    Join Date
    Jun 2002
    Posts
    7
    select * from table_name fetch first 2 rows only"

Posting Permissions

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