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 > SQL hlep

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-03, 23:18
Twinki Twinki is offline
Registered User
 
Join Date: Oct 2003
Posts: 5
SQL hlep

I just want to select 300 records from a table, how do I do that in SQL ?
is there a special option I can set? please help
Reply With Quote
  #2 (permalink)  
Old 12-01-03, 23:38
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Hi,

To select the first 300 rows from a table use

Select *
from table
where rownum < 301

However if your DB does not use support rownum, then add
GROUP BY list
HAVING COUNT(*) = x
where list = select list

or If you want to select all x rows past a rownum (ie, select the next 200 rows after row 300) then this will work, again replace rownum if DB doesn't support it. In addition you can replace the select..minus in the from clause with a view, if this will be done frequently.

select list
from
(select *
from table
minus
select *
from table
where rownum < 301)
group by list
having count(*) = x
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Last edited by r123456; 12-01-03 at 23:44.
Reply With Quote
  #3 (permalink)  
Old 12-01-03, 23:49
Twinki Twinki is offline
Registered User
 
Join Date: Oct 2003
Posts: 5
Thanks heaps!

Quote:
Originally posted by r123456
Hi,

To select the first 300 rows from a table use

Select *
from table
where rownum < 301

However if your DB does not use support rownum, then add
GROUP BY list
HAVING COUNT(*) = x
where list = select list

or If you want to select all x rows past a rownum (ie, select the next 200 rows after row 300) then this will work, again replace rownum if DB doesn't support it. In addition you can replace the select..minus in the from clause with a view, if this will be done frequently.

select list
from
(select *
from table
minus
select *
from table
where rownum < 301)
group by list
having count(*) = x
Reply With Quote
  #4 (permalink)  
Old 12-01-03, 23:59
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
correction,

rownum = x works fine.
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Last edited by r123456; 12-03-03 at 23:35.
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