In message <[EMAIL PROTECTED]>, Bob
<[EMAIL PROTECTED]> writes
>Hi Pete,
>I did sort one of my dbs by "year" when I was re-organizing, but luckily I'd 
>saved the sql dump.
>Why I sorted it was because it was originally a flat file, which I'd converted.
>It didn't have timestamps, just the dates.

I assume that you mean before you got the data into MySQL.  As far as I
know, you cannot SORT MySQL - to be pedantic, you cannot physically
change the order of the records.  You don't need to, you 'display' them
in a different order using indexes.  

There may be some obscure way of sorting, but it would probably involve
destroying the table, and rebuilding a copy of it, so wouldn't be done
on a working table.

>
>As you can guess, I'm still learning to use mysql databases *grin*.
>Thanks for the advice.
>
>Just got MAX() working after about 4hrs. I'd missed out the "AS logged" (It 
>was 
>nattering me. Don't need a haircut now!)

You don't need it, but the field returned by
SELECT UNIX_TIMESTAMP(MAX(logged)) FROM forum
(with no 'as logged') will be called 
"UNIX-TIMESTAMP(MAX(logged))"
and won't be easy to manipulate - hence the 'as logged'

>
>MAX(logged) to me, looks the more logical way of doing it.
>Any idea which would be the most efficient?

They are different:

>
>SELECT UNIX_TIMESTAMP(MAX(logged)) AS logged FROM forum

This one gives you the date of the most recent record.


>or
>SELECT UNIX_TIMESTAMP(logged) AS logged FROM forum ORDER BY logged DESC LIMIT

This one gives you the date of the n most recent records, in order from
newest to oldest.  You missed a number off after the LIMIT.

If there is an index on logged, then to the best of my knowledge, method
2 will be faster.  The database only has to read the last entry in the
index.


They are treated differently by SELECT.  But no-one will see the
difference - it will be half a squillisecond - or less.


-- 
Pete Clark

http://www.hotcosta.com
http://www.spanishholidaybookings.com




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/
 


Reply via email to