Usage of MySQL Order

Source: Internet
Author: User

Create the mysql_order_by_test data table according to the following table structure. We will use instance to tell you how to use MySQL order.

Order by uid ASC
Query data in the forward order of uid, that is, sort data in ascending order of uid
Order by uid DESC
Query data by uid in reverse order, that is, sort data by uid in ascending order

Let's see
SELECT * FROM mysql_order_by_test order by uid ASC

This statement is used to query data in the forward order of uid, that is, sort data in ascending order of uid.
The returned result is:

1 Zhang San 1
2 Li Si 2
3 Wang Erma Zi 1

Let's see
SELECT * FROM mysql_order_by_test order by uid DESC

This statement is used to query data in reverse order by uid, that is, sort data in ascending order by uid

The returned result is:
3 Wang Erma Zi 1
2 Li Si 2
1 Zhang San 1

SQL creation code:Copy codeThe Code is as follows: 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, 'zhang san', 1 );
Insert into mysql_order_by_test (uid, name, sex) VALUES (2, 'Li si', 2 );
Insert into mysql_order_by_test (uid, name, sex) VALUES (3, 'wang Erma sub', 1 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.