RE: [PHP-DB] Most Read Article
| From: | Gonzalez, Lorenzo | Date: | Mon, 05 Nov 2001 15:26:48 +0000 |
| Subject: | RE: [PHP-DB] Most Read Article | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14017@lists.php.net to get a copy of this message | ||
> How database intensive would this be if I had a lot of records in a
table?
Potentially Very. The 'order by' could happen before the limit, and
you're dead. Can anybody confirm this? Can't you do a subselect? (What
DB is it?) select article from articles where read = (select max(read)
from articles)
Honestly, If you'll be doing that a LOT (like it's not on a report, but
a main page), I'd cache the result globally and only issue the query
every X requests based on site load.
-Lorenzo
-----Original Message-----
From: Jordan Elver
Sent: Mon 11/5/2001 10:23 AM
To: me@shanewright.co.uk
Cc: PHP DB Mailing List
Subject: Re: [PHP-DB] Most Read Article
Thanks, works a treat.
How database intensive would this be if I had a lot of records
in a table?
Cheers,
Jord
On Monday 05 November 2001 09:47, you wrote:
> try this...
>
> SELECT title,reads FROM articles ORDER BY reads DESC LIMIT 1;
>
> That should do the trick.. (in mySQL or PostgreSQL anyway)
>
> --
> Shane
>
> On Monday 05 November 2001 9:36 am, you wrote:
> > Hi,
> > I'm trying to get the most read article out a table.
> > The table has a title column, a read column and some others.
> >
> > So I wanna SELECT the title from the table and the most read
figure.
> > I tried:
> >
> > SELECT title, MAX(reads) FROM articles
> >
> > This only gets the second most read article?! If I take out
the title
> > like:
> >
> > SELECT MAX(reads) FROM articles
> >
> > Then it gets the top article number but obviously not the
title.
> >
> > Can anyone shed some light?
> >
> > Cheers,
> > Jord
--
Jordan Elver
Web Developer
The InternetOne UK Ltd
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail:
php-list-admin@lists.php.net