Thank you all for your help. I think that is all I need to do is select
it by row.



> -----Original Message-----
> From: R. Hannes Niedner [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 28, 2003 2:02 PM
> To: Christopher Lyon; MySQL Mailinglist
> Subject: Re: sql query using select and row functions
> 
> On 1/28/03 12:26 PM, "Christopher Lyon" <[EMAIL PROTECTED]> wrote:
> 
> > I do have a timestamp field would I be better off using that?
Granted it
> > might not be the same amount of rows every time but how would that
work?
> >
> >
> > Select * from tbl_name where TIMESTAMP ( ) -3 hours;
> >
> 
> Well, that is not what you asked for you just wanted to get the last N
> records inserted into the database which is different from what you
asked
> now. Your original question is best answered with having an
autoincrement
> field in your table and do a:
> 
>     SELECT field........ FROM table WHERE whatever = don'tknow
>     ORDER BY autoincrement_field DESC LIMIT N;
> 
> Using the timestamp field to retrive all records inserted within the
last
> n
> years/months/weeks/days/hours/minutes/second requires some string
> conversion
> of the timestamp. Your best bet in that case is to look into the Date
and
> Time Functions:
> 
> Check comments also!
> <http://www.mysql.com/doc/en/DATETIME.html>
> <http://www.mysql.com/doc/en/Date_and_time_functions.html>
> 
> After reading through the excellent documentation it should be rather
> straight forward how to do it.
> 
> Hth/h
> 
> <SQL, QUERY, TABLE>
> 
> P.s. I also strongly recommend to keep the discussion on the list for
your
> benefit (there are much better experts on the mysql list than me) but
also
> for the benefit of others with a similar problem (although there is a
> rather
> big lag from posting to appearing on the list). The list archives also
> getting way to little attention.
> 
> 
> >
> >> -----Original Message-----
> >> From: R. Hannes Niedner [mailto:[EMAIL PROTECTED]]
> >> Sent: Tuesday, January 28, 2003 11:50 AM
> >> To: Christopher Lyon; MySQL Mailinglist
> >> Subject: Re: sql query using select and row functions
> >>
> >> On 1/28/03 8:26 AM, "Christopher Lyon" <[EMAIL PROTECTED]> wrote:
> >>
> >>> I am trying to do an sql query and am trying to select the last x
> > rows
> >>> from the database. I see the limit function but that seems like
that
> > is
> >>> from the first row down. I want to start from the last row to the
> > first
> >>> row. So, selecting the last 5 rows for instance? Can this be done?
> >>
> >> The easiest way is probably to add an ORDER BY field DESC into your
> > SQL
> >> statement. If you use an autoincrement field you could use that
> > otherwise
> >> add a field  and make it TIMESTAMP.
> >>
> >> Hth/h
> >>
> >
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to