 ShowAll Questionssorted byDate Posted kkr.dev

# Sorting aggregate results ..Urgent

Hi All,

I need to know is it possible to sort aggregate results in sorting?

Thanks Best Answer chosen by Admin (Salesforce Developers)  Chiz
```List<AggregateResult> aggSummary =
[
SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
FROM qq__c qq
GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
ORDER BY sum(x1__c)
];```

Yes. But put sum(xx1) instead of simple "xx1". Chiz
```List<AggregateResult> aggSummary =
[
SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
FROM qq__c qq
GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
ORDER BY x2__c
];```

This query works perfect. If you was askign for ORDER BY. kkr.dev
```List<AggregateResult> aggSummary =
[
SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
FROM qq__c qq
GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
ORDER BY xx1
];```

﻿Thanks for your reply ..I need Order by XX1. Is this possible ? Chiz
```List<AggregateResult> aggSummary =
[
SELECT sum(x1__c) xx1, x2__c xx2, x2__r.Name xx2Name, x2__r.x2_x__c x2x
FROM qq__c qq
GROUP BY x2__r.Name, x2__r.x2_x__c, x2__c
ORDER BY sum(x1__c)
];```

Yes. But put sum(xx1) instead of simple "xx1".

This was selected as the best answer kkr.dev

Thanks a lot.I appreciate it.