mysql 去掉默认排序,更改MySQL的默认排序行为

I have a table in my database.

+--------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+--------+-------------+------+-----+---------+----------------+

| id | int(11) | NO | PRI | NULL | auto_increment |

| rollno | int(11) | NO | | NULL | |

| name | varchar(20) | NO | | NULL | |

| marks | int(11) | NO | | NULL | |

+--------+-------------+------+-----+---------+----------------+

By default if I query

select * from students;

Shows result sorted by id INT (auto-increment).

+----+--------+------------+-------+

| id | rollno | name | marks |

+----+--------+------------+-------+

| 1 | 65 | John Doe | 89 |

| 2 | 62 | John Skeet | 76 |

| 3 | 33 | Mike Ross | 78 |

+----+--------+------------+-------+

3 rows in set (0.00 sec)

I want to change default sorting behaviour and make rollno the default sorting field, how do I do this?

解决方案

There is no default sort order!

The DB returns the data in the fastest way possible. If this happen to be the order in which it is stored or a key is defined then this is up to the system. You can't rely on that.

Think about it: Why would the DB use performace to order something by default if you don't need it ordered. DBs are optimised for speed.

If you want it being ordered then you have to specify that in an order by clause.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值