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
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!