How to Sort both in Ascending and Descending order in SOQL?

Sample:

SELECT Name, CMR_Number__c FROM Account ORDER By Name ASC, AccountSite DESC

Using the above SOQL, accounts will be sorted by Name in ascending order and then by AccountSite in descending order.

4 comments:

  1. Hi,
    Can you suggest how to sort values in text field and to display them in visualforce?

    text field which numeric values like 1, 19, 35 etc. Visualforce page displays these values as
    1
    35
    19

    how can I sort them as 1,19,35

    ReplyDelete
  2. My query look like :
    [select id, Name, high_months__c, low_months__c, Account_Number__c from Company_Account__c where Account__c = :accId Order By Account_Number__c DESC];

    Above, I want to sort by Account_Number__c which is text field with data as numbers but in visualforce I am not getting sorted data, please help?

    ReplyDelete
    Replies
    1. Hi, If you want in Ascending order use ASC instead of DESC.

      Delete
  3. wow!
    This blog is fantastic,
    Lots of Stuff Here!

    I used to visit this blog to resolve my issues and other,
    Thanks for making such a wonderful blog,

    ReplyDelete