[nycphp-talk] selecting/deleting all oldest entries in mysql.
Christopher R. Merlo
cmerlo at turing.matcmp.ncc.edu
Mon Mar 10 23:48:36 EST 2003
On 2003-03-10 20:41 -0500, Nasir Zubair <lists at ny-tech.net> wrote:
> Hi all,
>
> I need to create a small logger, for our work place, that will log staff's
> IP addresses and host names. What I'm trying to do is to log last X accesses
> to an online helpdesk, 24 for example.
>
> I'm having trouble coming up with a query to select/delete the oldest entry
> when a X+1st entry, (25th for the above number), is inserted.
>
> Can anyone hint me on how to go about doing it?
Reliable method: Have a datetime field in the table, and update that
with the current time every time somebody logs in. Then you can just
do a "select * from my_table order by name_of_datetime_field" and pull
off the first (last?) entry.
Unreliable method: If you just do a "select *", things tend to show
up in the order they were inserted. So, just take the last one.
HTH.
-c
--
cmerlo at turing.matcmp.ncc.edu http://turing.matcmp.ncc.edu/~cmerlo
An apple every eight hours will keep three doctors away.
More information about the talk
mailing list