mike12255 Posted January 23, 2009 Share Posted January 23, 2009 I have a database, that only contains 4 things inside it. Is there a way that when i go to add a new entry to it, searches for the oldest entry in 'headernews' and deleates it? Quote Link to comment Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 Can you show us your database? field names... Quote Link to comment Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 How do you determine the oldest entry? Is there a date field? Quote Link to comment Share on other sites More sharing options...
Adam Posted January 23, 2009 Share Posted January 23, 2009 If you have a field which has an auto_incrementing value, you could use something like: DELETE FROM table_name ORDER BY field_name ASC LIMIT 1; This may well work in other situations but I've not tested! Also it doesn't necessarily need to be an auto_incrementing field, just an ASCending (or DESCending) pattern that you can rely on to be in order of old to new (or new to old). Adam Quote Link to comment Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 sorry, just wrote an exam and school and got back, so lets say that the database looked like below, probually wont but something similar: you guys say theres a way to deleate it using the date? btw idk if that is setup right im not the best in mysql Quote Link to comment Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Sure, just order by date. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 ok, so would that put oldest as first or as last? Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted January 23, 2009 Share Posted January 23, 2009 that depends if your sort ASC or DESC Quote Link to comment Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 well i've never even heard of DESC soo i guess the other way? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Look up the ORDER BY function for MySQL (you haven't stated what DB you are using). Quote Link to comment Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 ok thanks, setting this as solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.