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);