Make sure that your table has a column of type timestamp.  That
provides the same functionality as a datetime field set to now(),
but without your having to manually set it.  (Warning, though: a
timestamp field will update anytime the record is updated, unless
you specifically set it to its current value).

Then,

  SELECT *
  FROM your_table
  WHERE
    time_stamp = (SELECT MAX(time_stamp) FROM your_table);
    
You can also use an auto_increment ID field to accomplish this.


> Perhaps you can create a date field with the default value being
> Now()-- then sort by said field.
> 
> see also:
> http://www.mysql.com/doc/en/Date_and_time_functions.html
> 
> > >>> [EMAIL PROTECTED] 10/20/03 12:09 PM >>>
> > I'm creating a simple mySQL database that is being populated by a 
> > perl script.  Each entry will corresponds to an event that is 
> > happening on another machine.  I'm looking for an SQL query that 
> > will return the most recent entry and I have no way of knowing 
> > when that might have been.  It may have been two hours ago, or two 
> > weeks.  
> >
> > The only way I can think of is to ask for the list to be sorted 
> > and take the first row, but this seems wrong in every way, 
> > especially once the list starts to grow.
> >
> > Any ideas?

____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to