Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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-02-03, 00: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-02-03, 00: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-02-03 at 00:44.
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 00: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-02-03, 00: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-04-03 at 00: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

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