[thelist] php/mysql get next two records
Burhan Khalid
thelist at meidomus.com
Tue Feb 8 00:40:52 CST 2005
> -----Original Message-----
> From: Mark Groen [mailto:markgroen at gmail.com]
> Sent: Monday, February 07, 2005 5:14 PM
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] php/mysql get next two records
>
> > > Can you use TOP in mySQL?
> > [/snip]
> >
> > No, but it does support a "LIMIT" clause which does the
> same in it's
> > simplest syntax:
> >
> > SELECT
> > <whatever fields>
> > FROM
> > myTable
> > WHERE
> > myField => myCriteria
> > ORDER BY
> > myField
> > LIMIT 3
> >
> > (It does have to be specified after the ORDER clause.)
> >
> > For more details:
> > http://dev.mysql.com/doc/mysql/en/select.html
>
> I think I will try Burhan's idea, the records may need a wee
> bit of extra sorting and pulling them all out for one day in
> a chunk would work for that, (there isn't something on every
> hour, lots of blank spots), thanks everyone!
>
> I rather do like the sql way though, more elegant...hmmm
You know, even I like the SQL approach. However, I don't know in the long
run if its efficient. I mean, is it better to have one query (one hit to
the database), then do the sorting, etc. in PHP (or whatever your poison) --
than having a query to the database on each condition (so if you wanted four
days, LIMIT 4, five days, LIMIT 5, etc.) I was always under the impression
that database access was one of the slowest parts of an application; that it
can be a good cause for a bottleneck.
Regards,
Burhan
More information about the thelist
mailing list