[ILUG] OT: SQL query problem.....
Glen Gray
gleng at bsolved.com
Thu Jun 10 20:54:59 IST 1999
I have a bit of a problem at work. I have an Oracle table that acts as a
message queue for part of a project I've been working on. I'm having a
bit of trouble with what I thought would have been a simple SQL query.
Basically I need to be able to grab the last n amount of records. Or to
put it another way, given a record's key, I need to retrieve the
previous n records, where n is the number of records I want (obvious I
know).
So any ideas. I need it as basic SQL like "select * from table where
recordkey=124".
I've tried various attempts, the best way I could think of was to limit
the rownum to <=n and reverse the order. But the ordering only works
after result has been created.
e.g.
select
*
from
record_table
where
recordid < (select max(recordid) from record_table)
and rownum<=10
order by
recordid desc
I'd appreciate any help or tips.
Cheers
Glen
More information about the ILUG
mailing list