On 6/19/2005, "Bob" <[EMAIL PROTECTED]> wrote:

>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.
>
>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!)
>
>MAX(logged) to me, looks the more logical way of doing it.
>Any idea which would be the most efficient?
>
>SELECT UNIX_TIMESTAMP(MAX(logged)) AS logged FROM forum
>or
>SELECT UNIX_TIMESTAMP(logged) AS logged FROM forum ORDER BY logged DESC LIMIT
>
>Regards, Bob.
>
>

Bob - As Pete tried to tell you, there's really no such thing as sorting
a retational data base (like MySQL). You can insert a set of records
that are already sorted, but as soon as you insert even one additional
record,  the sort order is undefined.

Instead, you perform efficient searches by creating indexes on certain
fields.  Even indexes *can* cause performance degradation (when
inserting or updating), so don't overdo it. However, if you will
frequently perform queries based on the "logged" column, by all means,
this column should be indexed.

Once the column is indexed, your initial query will actually be fastest
in a large data base:

select *
from table
where ....
order by indexed_date_column desc limit 1;

hth,
Mike


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