You can use ORDER BY to sort one or more fields. The default value is the ascending order (ASC). When you sort data, you must use a LIMIT clause to improve the sorting performance.
Syntax
select:
SELECT [ DISTINCT ]
{ projectItem [, projectItem ]* }
FROM tableExpression
ORDER BY { orderByItem [ASC|DESC] [,OrderByItem ASC|DESC]* }
LIMIT N
OFFSET MExamples
Sort data in the simplest manner:
SELECT nid, brand, price, size FROM phone ORDER BY price LIMIT 1000Sort data in ascending order:
SELECT nid, brand, price, size FROM phone ORDER BY price ASC LIMIT 1000Sort data based on multiple fields:
SELECT nid, brand, price, size FROM phone ORDER BY size DESC, price DESC LIMIT 1000Return the records of the eleventh to twentieth prices in the price sorting result:
SELECT nid, brand, price, size FROM phone ORDER BY price DESC LIMIT 10 OFFSET 10Return the data of 10 random products without sorting data:
SELECT nid, brand, price, size FROM phone LIMIT 10