+ Start a Discussion
Nikki_tcsNikki_tcs 

Sorting in asc/ desc in soql

Hi,

 

How can i sort the list of values (ascending /descending) using soql query? 

 

 

SELECT Id, CommentBody, CreatedById, createdBy.communityNickname, CreatedDate, IdeaId 
                                          FROM IdeaComment 
                                          WHERE IdeaId in :ideaIds
                                          AND createdById = :createdById];

 

Can anyone provide the syntax?

 

Thanks,

Nik 

Best Answer chosen by Admin (Salesforce Developers) 
incuGuSincuGuS

Here you go man!

 

SELECT Id, FirstName FROM Lead ORDER BY Name DESC LIMIT 10

 

Remove the limit clause if you want to query all.

Gaston.

All Answers

JimRaeJimRae

Actually, I think you would want to use the "order by" keyword.

 

somthing like this:

 

select id,name,billingcity from Account order by billingcity asc

 

 

Ken_KoellnerKen_Koellner

RTFM, use an "order by" clause. 

 

One caveat that miight not be listed in the manual.  If you are sorting picklist fields, the will not sort alphabetically.  They will sort based on the order defined in the picklist.

 

incuGuSincuGuS

Here you go man!

 

SELECT Id, FirstName FROM Lead ORDER BY Name DESC LIMIT 10

 

Remove the limit clause if you want to query all.

Gaston.

This was selected as the best answer