You need to sign in to do that
Don't have an account?
Carlos Sabado Cortes
How to use Agregated query in child soql?
Hello,
I am trying to create a soql like this:
SELECT Id, attr1, attr2, attr3
FROM apiObject
WHERE attr1 IN
(SELECT attr1 FROM apiObject WHERE attr1 != null GROUP BY attr1, attr2, attr3 HAVING count(id) > 1)
But it shows this excepction:
ERROR at Row:2:Column:79
expecting a right parentheses, found 'GROUP'
Anybody could help me?
I am trying to create a soql like this:
SELECT Id, attr1, attr2, attr3
FROM apiObject
WHERE attr1 IN
(SELECT attr1 FROM apiObject WHERE attr1 != null GROUP BY attr1, attr2, attr3 HAVING count(id) > 1)
But it shows this excepction:
ERROR at Row:2:Column:79
expecting a right parentheses, found 'GROUP'
Anybody could help me?
Sorry for this issue you are encountering.
May I suggest you please check with below links which has the detailed explanation on how to build and use aggregate functions.
- https://apexcoder.com/2016/01/02/how-to-use-soql-query-with-nested-soql-aggregate-functions-order-by-group-by-having-offset-and-limit/
- https://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/
Please let us know if this helps.Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra
You can try the following Query :
Please mark as best answer if it helps you.
Thank You
Ajay Dubedi
Thank you for the anwser but they aren´t the solution. The target for this query is retrieve id from aggregate query. In first time i developed a batch with this query " (SELECT attr1 FROM apiObject WHERE attr1 != null GROUP BY attr1, attr2, attr3 HAVING count(id) > 1)" and in the excute i called this I am trying to create a soql like this: "SELECT Id, attr1, attr2, attr3 FROM apiObject WHERE attr1 IN ;setID", but the problem is the limits because sometimes the 2º query returns > 50k rows, i have thought in create a second batch but i don´t like this solution.
Thank you for you help.
Carlos