时间:2021-07-01 10:21:17 帮助过:76人阅读
ORDER BY uid ASC
按照uid正序查询数据,也就是按照uid从小到大排列
ORDER BY uid DESC
按照uid逆序查询数据,也就是按照uid从大到小排列
我们来看
SELECT * FROM mysql_order_by_test ORDER BY uid ASC
这条语句是按照uid正序查询数据,也就是按照uid从小到大排列
返回的结果就是:
1 张三 1
2 李四 2
3 王二麻子 1
我们来看
SELECT * FROM mysql_order_by_test ORDER BY uid DESC
这条语句是按照uid逆序查询数据,也就是按照uid从大到小排列
返回的结果是:
3 王二麻子 1
2 李四 2
1 张三 1
SQL创建代码:
CREATE TABLE IF NOT EXISTS mysql_order_by_test (
uid int(10) NOT NULL AUTO_INCREMENT,
name char(80) NOT NULL,
sex tinyint(1) NOT NULL,
KEY uid (uid)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(1, '张三', 1);
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(2, '李四', 2);
INSERT INTO mysql_order_by_test (uid, name, sex) VALUES(3, '王二麻子', 1);