|
|
 |
Re: FN-FORUM: Mysql syntax help
date posted 1st May 2008 16:11
> On Thu, 2008-05-01 at 16:17 +0000, Nigel Rogers wrote:
> > Hi, I think this is a simple question:
> >
> >
> > I have a simple query that requests the 3 most recent album entries
> > from a mysql database
> >
> > $maxRows_Albums = 3;
> >
> >
> > which i order by recent first...
> >
> > $query_Albums = "SELECT * FROM albumlist ORDER BY id DESC";
> >
> >
>
> Is id always greater for later entries? (You'd get that if you had set
> the autoincrement attribute on that field). If so then you'd get what
> you want by selecting all but the largest id entry and then limiting
> your results to the next three. So something like:
>
> SELECT * FROM albumlist where id < ( select max(id) from albumlist )
> order BY id DESC limit 3
>
> (the limit 3 is mysql dialect)
>
Actually, the limit 2,3 solution other posters suggested is both simpler
and cleaner than this (if you're using Mysql). Didn't know you could do
that...
Graham
|
 |
|