MySQL order by usage share _mysql

Source: Internet
Author: User
To create the Mysql_order_by_test datasheet by following the table structure below, let's use the example 1.1 to tell you the MySQL order by usage.

ORDER BY UID ASC
Query the data according to the UID positive order, that is, by the UID from small to large arrangement
ORDER BY UID DESC
Query the data in reverse order, which is sorted by UID from large to small

Let's see
SELECT * from Mysql_order_by_test ORDER by UID ASC

This statement queries the data according to the UID positive sequence, which is the order of the UID from small to large
The result of the return is:

1 Sheets 31
2 Lee 42
3 King two-Pock 1

Let's see
SELECT * from Mysql_order_by_test ORDER by UID DESC

This statement queries the data in reverse order, which is sorted by UID from large to small

The result returned is:
3 King two-Pock 1
2 Lee 42
1 Sheets 31

SQL Creation Code:
Copy Code code as follows:

CREATE TABLE IF not EXISTS mysql_order_by_test (
UID Int (a) not NULL auto_increment,
Name Char (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, ' John ', 1);
INSERT into Mysql_order_by_test (UID, name, Sex) VALUES (2, ' Dick ', 2);
INSERT into Mysql_order_by_test (UID, name, Sex) VALUES (3, ' King two-pox ', 1);

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.