Limit record count

Started by Sean Z.over 18 years ago2 messagesgeneral
Jump to latest
#1Sean Z.
sean09182006@yahoo.com

Hi,

I need to write a maintenance function to delete oldest records of a table, leaving only a certain number of records, say 50. The task should run once per day. How can I write it?
The oldest record carries the smallest ID.

Thanks a lot!
Sean

____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

#2Rodrigo Gonzalez
rjgonzale@gmail.com
In reply to: Sean Z. (#1)
Re: Limit record count

DELETE FROM <table> WHERE <id> NOT IN (SELECT <id> FROM <table> ORDER BY
<id> DESC LIMIT 50)

Sean Z. escribió:

Show quoted text

Hi,

I need to write a maintenance function to delete oldest records of a
table, leaving only a certain number of records, say 50. The task
should run once per day. How can I write it?
The oldest record carries the smallest ID.

Thanks a lot!
Sean

------------------------------------------------------------------------
Never miss a thing. Make Yahoo your homepage.
<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs&gt;