MySQL sort by a column by default in phpMyAdmin

匿名 (未验证) 提交于 2019-12-03 02:34:02

问题:

I added a new index in my table and now phpMyAdmin is sorting the rows by that column by default. How do I make phpMyAdmin sort the rows by the id column instead of the url column by default?

CREATE TABLE IF NOT EXISTS `links` (   `id` int(11) unsigned NOT NULL auto_increment,   `url` varchar(255) NOT NULL default '',   PRIMARY KEY  (`id`),   UNIQUE KEY `url` (`url`) ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=343959 ; 

回答1:

You can resolve this issue by adding default order by to the tableusing the alter table query.

QUERY: alter table links order by id;

If you not specify any order by clause in where clause, then rows will sort by default "id" column.



回答2:

There is no "default" ordering of rows. If you want a query to return rows in a particular order, then you must use an order by clause.

You cannot even depend on rows being returned by the primary key order. In fact, with updates/deletes/inserts on the table, this will often not be true.

If you want a query to return rows in a particular order, then you must use an order by clause (I realize I repeated that). The only exception is that MySQL (in violation of the standard) guarantees the ordering of results when using group by.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!