NYCPHP Meetup

[nycphp-talk] MySQL primary sort oddity

John Nunez john at cyber-ny.com
Mon Jan 31 22:23:45 EST 2005


I had this happen to me but not sure why.  I think I might have changed 
the ID on a record or something like that.  The easiest way to fix this 
is in phpMyAdmin goto the Operations tab, there is a drop down with the 
text "Alter table order by:" and select the ID field.  Note: that if 
you do this for another type of field (i.e. Username) it will not keep 
a sorting it for you with each entry.  It's a one-time disk sort.

Thanks,
John Nunez
Cyber-NY Interactive
212-475-2721
www.cyber-ny.com
john at cyber-ny.com


On Jan 30, 2005, at 6:20 PM, Hans Zaunere wrote:

>
>> Right, so how is it that an auto_increment wouldn't sort by the id
>> number?  Because if it's being sorted by the order it got entered,
>> then it should still be in order.  At least that clears up a few
>> things for me.
>
> auto_increment isn't dependant on sorting.  It's an internal counter 
> that is maintained in the table structure.  The order by which records 
> appear when a SELECT is run without an ORDER BY is the order in which 
> they lay in the on-disk datafile.  An auto_increment column, on the 
> other hand, is just a counter.
>
>> On a side note, anyway to have phpMyAdmin default sort by primary key?
>
> Not that I know of, but you should always specify an ORDER BY when you 
> want something sorted anyway, and not depend on some automatic 
> behavior.
>
>
> H
>
>
> _______________________________________________
> New York PHP Talk
> Supporting AMP Technology (Apache/MySQL/PHP)
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>




More information about the talk mailing list