function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Charlone Gianan 1Charlone Gianan 1 

How to sort DESC ?

Can you guys help me how can I sort this subquery Descending? I tried to put ORDER BY DESC but nothing happen. 
Employee_Skills__c (lookup from Contact(Employee)).
SELECT Name, (SELECT Skill_ID__r.Name, Proficiency__c FROM Employee_Skills__r) FROM Contact

 for (Employee_Skills__c setSkill1 : [SELECT Employee_ID__c FROM Employee_Skills__c WHERE (Skill_ID__r.Name LIKE :'%' + skillName + '%') AND (Proficiency__c >= :proficiency.left(1)) AND (Year_of_Experience__c  LIKE :yearsOfExperience + '%') ORDER BY Proficiency__c DESC ] ) {
                skill1.add(setSkill1.Employee_ID__c);                                                         
 }              
              
Deepak Pandey 13Deepak Pandey 13
order by CreatedDate DESC
 
Charlone Gianan 1Charlone Gianan 1
Hi Deepak,

We want to sort it by Proficiency__c which is a field in the lookup. 
Deepak Pandey 13Deepak Pandey 13
filter will be always by date field. modified or created date or etc
Charlone Gianan 1Charlone Gianan 1
Is it possible to sort by using subquery field (lookup) ? 
Deepak Pandey 13Deepak Pandey 13
 for (Employee_Skills__c setSkill1 : [SELECT Employee_ID__c FROM Employee_Skills__c WHERE (Skill_ID__r.Name LIKE :'%' + skillName + '%') AND (Proficiency__c >= :proficiency.left(1)) AND (Year_of_Experience__c  LIKE :yearsOfExperience + '%') ORDER BY Proficiency__c DESC ] ) {
                skill1.add(setSkill1.Employee_ID__c);                                                         
 }              

your query please hold it on set and check set index wise what come in set[0].
LBKLBK
Hi Charlone,

If you want to SORT your data by Proficiency__c, you need to change the BASE query.

Instead of
SELECT Name, (SELECT Skill_ID__r.Name, Proficiency__c FROM Employee_Skills__r) FROM Contact

Try this.
SELECT Contact__r.Name, Skill_ID__r.Name, Proficiency__c FROM Employee_Skills__c ORDER BY  Proficiency__c