Overview
You can use ORDER BY to sort one or more fields. The default value is ASC. ASC specifies the ascending order. When you sort data, use a LIMIT clause because the sorting performance is low when you sort data.
Supported versions
OpenSearch Retrieval Engine Edition whose HA3 version is V3.7.0 or later
Syntax
select:
SELECT [ DISTINCT ]
{ projectItem [, projectItem ]* }
FROM tableExpression
ORDER BY { orderByItem [ASC|DESC] [,OrderByItem ASC|DESC]* }
LIMIT N
OFFSET M
Examples
Sort data in a simple manner:
SELECT nid, brand, price, size FROM phone ORDER BY price LIMIT 1000
Sort data in ascending order or descending order:
SELECT nid, brand, price, size FROM phone ORDER BY price ASC LIMIT 1000
Sort multiple fields:
SELECT nid, brand, price, size FROM phone ORDER BY size DESC, price DESC LIMIT 1000
Return 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 10
Return the data of 10 random products without sorting data:
SELECT nid, brand, price, size FROM phone LIMIT 10