The
ORDER BY
clause in SOQL is used to sort the records retrieved in the ascending or descending order.
An ascending order sample query is given as follows:
SELECT Name, Amount FROM Opportunity ORDER BY Name ASC
The preceding query will retrieve all the Opportunity
instances arranged in the ascending order of the name. The following screenshot is the output of the SOQL execution:
A descending order sample query is given as follows:
SELECT Name, Amount FROM Opportunity ORDER BY Name DESC
The preceding query will retrieve all the Opportunity
instances arranged in the descending order of the name. The following screenshot is the output of the SOQL execution: