Home Database Mysql Tutorial MySQL Order By用法分享_MySQL

MySQL Order By用法分享_MySQL

Jun 01, 2016 pm 01:23 PM
data sheet

bitsCN.com 先按照下面的表结构创建mysql_order_by_test数据表,我们用实例一点一点告诉你,MySQL order by的用法。

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);
bitsCN.com

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Data table compression technology in MySQL Data table compression technology in MySQL Jun 16, 2023 am 08:16 AM

Data table compression technology in MySQL

mysql modify data table name mysql modify data table name Jun 20, 2023 pm 05:52 PM

mysql modify data table name

Data table DDL operation technology in MySQL Data table DDL operation technology in MySQL Jun 15, 2023 pm 07:55 PM

Data table DDL operation technology in MySQL

How to calculate the average value of numeric columns in a data table using MySQL's AVG function How to calculate the average value of numeric columns in a data table using MySQL's AVG function Jul 24, 2023 pm 09:52 PM

How to calculate the average value of numeric columns in a data table using MySQL's AVG function

Data table reloading techniques in MySQL Data table reloading techniques in MySQL Jun 15, 2023 pm 11:28 PM

Data table reloading techniques in MySQL

How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables Nov 08, 2023 pm 06:57 PM

How to implement MySQL underlying optimization: horizontal and vertical splitting strategies for data tables

How to use the MAX function in MySQL to find the largest value in the data table How to use the MAX function in MySQL to find the largest value in the data table Jul 25, 2023 pm 09:49 PM

How to use the MAX function in MySQL to find the largest value in the data table

Optimization techniques for data table and data column segment parameters in MySQL Optimization techniques for data table and data column segment parameters in MySQL Jun 14, 2023 pm 12:45 PM

Optimization techniques for data table and data column segment parameters in MySQL

See all articles