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
Shilpa Goyal 9Shilpa Goyal 9 

sort the values on the basis of nested query column

Hi everyone, 
I have a query with sub query and i want sorting on column of sub query.

Here is my query
 List<Responsibility__c> rList=[select Name,Type__c,Description__c,                                        (SELECT Description__c FROM  Responsibility_Details__r)                                    
 from Responsibility__c     where Skill_Matrix__r.Name=:role1 and Type__c!=null order by Type__c,Name];

I want the sorted values of description of sub query which is coming from responsibility_details__r .

how can i do that. if someone can help me.
thanks
Shilpa     
mukesh guptamukesh gupta
Hi Shilpa,

Please use below code:-
 
List<Responsibility__c> rList=[select Name,Type__c,Description__c,                                        
 (SELECT Description__c FROM  Responsibility_Details__r ORDER BY Description__c DESC NULLS LAST)                                    
 from Responsibility__c     where Skill_Matrix__r.Name=:role1 and Type__c!=null order by Type__c,Name];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Shilpa Goyal 9Shilpa Goyal 9
Hi Mukesh, thaks fro quick response
but its giving me this error if i try to put order by clause in inner query

field 'Description__c' can not be sorted in a query call
mukesh guptamukesh gupta
Hi Shilpa,

I have tested below code my side:-
 
List<Opportunity> opp = [SELECT Amount, Id, Name,
  (
    SELECT Quantity, ListPrice,
 PricebookEntry.UnitPrice, PricebookEntry.Name 
    FROM OpportunityLineItems ORDER BY PricebookEntry.Name DESC NULLS LAST
  )
FROM Opportunity LIMIT 1];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh