LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] OT: SQL query problem.....

[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
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell