Results 1 to 4 of 4

Thread: select range

  1. #1
    Join Date
    Jul 2003
    Location
    Netherlands
    Posts
    29

    Unanswered: select range

    Hi there,

    Suppose I have like 100 records sorted on a unique ID. How can I select, for example, records 30 to 40 from this set? Note: the ID values are NOT in one range though. They could be, for example, 1,2,5,6,7 etc.
    Bye,

    Jeroen

    A 3D editor project
    www.delgine.com

  2. #2
    Join Date
    Mar 2004
    Location
    INDIA
    Posts
    1

    Arrow Reply

    U may add a column to hold sequence's running values(it has continuous values) & wrt this column u may specify the range.

    (while using rownum ,it only refer from beginning of the table ie from first row itself.)

    Hope it works.

  3. #3
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Oracle 9i,

    Select columns
    from
    (select columns, RANK() OVER (ORDER BY column) RN from table) V
    where V.RN BETWEEN X AND Y;
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    In almost any SQL dialect, you can use:
    PHP Code:
    SELECT *
       
    FROM myTable AS a
       WHERE 
    (SELECT Count(*)
          
    FROM myTable AS b
          WHERE  b
    .id <= a.idBETWEEN 30 and 40 
    ...but that is a really poor use of the SQL engine. You are really better off to retrieve the whole set, then filter out the rows that interest you on the client.

    -PatP

Posting Permissions

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