If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > select range

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-04, 05:40
JeroenNL JeroenNL is offline
Registered User
 
Join Date: Jul 2003
Location: Netherlands
Posts: 29
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
Reply With Quote
  #2 (permalink)  
Old 03-06-04, 06:36
sulax sulax is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 03-06-04, 12:34
r123456 r123456 is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 03-07-04, 00:08
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On