Q: How to select 20th to 100th rows?

Q: How to select 20th to 100th rows?

Post by Alton Ayer » Fri, 15 Aug 1997 04:00:00



You can do this:

select * from (select rownum seq, mytable.* from mytable)
where seq between 25 and 250

This assumes you don't care that the records are not ordered, you just
want the 25th thru 250th as they come from the database.


> Say, I have a table with 1000 records in it. I have two numbers, x = 25
> and y = 250. I want to select the 26th. to 250th. rows of this table.

> In SQL how can I do this without using a SEQUENCE column in the table?

> E-mailed replies much appreciated. Thanks,

> --
> amit bhati

 
 
 

Q: How to select 20th to 100th rows?

Post by Amit Bha » Fri, 15 Aug 1997 04:00:00


Say, I have a table with 1000 records in it. I have two numbers, x = 25
and y = 250. I want to select the 26th. to 250th. rows of this table.

In SQL how can I do this without using a SEQUENCE column in the table?

E-mailed replies much appreciated. Thanks,

--
amit bhati

 
 
 

Q: How to select 20th to 100th rows?

Post by terryg » Fri, 15 Aug 1997 04:00:00



> Say, I have a table with 1000 records in it. I have two numbers, x = 25
> and y = 250. I want to select the 26th. to 250th. rows of this table.

> In SQL how can I do this without using a SEQUENCE column in the table?

> E-mailed replies much appreciated. Thanks,

> --
> amit bhati

The implication here is that nothing orders the
data in the table, yet you want the 26 to 250th
rows.  I believe that Oracle doesn't guarantee
the order of data retrieved if you have nothing
to order by. So, even if you just select everything
and look at the 26 through 250th rows, there's
no guarantee that the 26-250 subset would be
consistent from one run to another.
I believe you should look for an alternative such
as adding a sequence field.

Cheers,
TRG

 
 
 

Q: How to select 20th to 100th rows?

Post by Janek Metsalli » Sat, 16 Aug 1997 04:00:00


Hi,

Quote:> > Say, I have a table with 1000 records in it. I have two numbers,
> > x = 25 and y = 250. I want to select the 26th. to 250th. rows of
> > this table.

> > In SQL how can I do this without using a SEQUENCE column in the
> > table?
> select * from (select rownum seq, mytable.* from mytable)
> where seq between 25 and 250
> This assumes you don't care that the records are not ordered, you just
> want the 25th thru 250th as they come from the database.

And if you care of the order of records:

select t1.name_every_col
from
   table_1 t1
  ,table_1 t2
where
  t1.order_col >= t2.order_col
group by t1.name_every_col
having count(t2.rowid) between x and y
;

But this is quite expensive query!

Regards,
Jan