Hi Pete,
Just thought I'd let you know that I used "Giztimer" (it's just a ready made
class timer which you can start and stop etc.) to test the 2 options.
$result = mysql_query("SELECT UNIX_TIMESTAMP(MAX(logged)) AS logged FROM
forum");
$result = mysql_query("SELECT UNIX_TIMESTAMP(logged) AS logged FROM forum ORDER
BY logged DESC LIMIT 1");
MAX(logged) came out at more than twice the speed of ORDER BY logged DESC LIMIT
1
MAX(logged) = 0.0023 Secs (average)
ORDER BY logged DESC LIMIT 1 = 0.0052 (average)
I did the test purely by getting the last record field, nothing else.
That's with my small database and a very slow processor.
In my case, it doesn't matter and I'll stick with the preferred method.
Just did for practice really.
Forum table from sql dump:-
CREATE TABLE `forum` (
`who` varchar(100) NOT NULL default '',
`city` varchar(100) NOT NULL default '',
`message` text NOT NULL,
`logged` varchar(14) NOT NULL default '',
PRIMARY KEY (`logged`)
) TYPE=MyISAM;
logged = TIMESTAMP(14);
The finished article, the message board:
http://www.circlecity.co.uk/sleepdesk/index.php
All my own work (with the help of this group),
Regards, Bob.
----- Original Message -----
From: "Pete" <[EMAIL PROTECTED]>
> I am not sure (and, if I am totally honest, can't be arsed testing!) how
> much faster than MAX(), which could well use the same index.
>
> But DESC LIMIT is the preferred method, because everyone can read the
> code.
>
> --
> Pete Clark
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/