+ Start a Discussion
Sylvain@RibbonFishSylvain@RibbonFish 

SOQL and Group By (relationship) Error

Hello,

I got this query:

Select Family__r.Name, Family__c, Name From Product2  (Ok Works)

 

 

Select Family__r.Name, Family__c, Name From Product2 Group By Family__r.Name, Family__c, Name (Not Working)

Error Message: MALFORMED_QUERY - duplicate alias: Name.

 

Ok I got it, Name and Name but if I remove it:

Select Family__r.Name, Family__c From Product2 Group By Family__r.Name, Family__c (ok works)

But the problem is I need Name of the product as well.

Did someone have an idea?

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
nj07nj07

Hi,

 

You would need to use a different alias for Name so that your query understands that its two different Name field.

 

[Select Family__r.Name, Family__c, Name name2 From Product2 Group By Family__r.Name, Family__c, Name ];

The above Query should work for you.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Thanks,

Nilesh Jain

All Answers

nj07nj07

Hi,

 

You would need to use a different alias for Name so that your query understands that its two different Name field.

 

[Select Family__r.Name, Family__c, Name name2 From Product2 Group By Family__r.Name, Family__c, Name ];

The above Query should work for you.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Thanks,

Nilesh Jain

This was selected as the best answer
Dhaval PanchalDhaval Panchal
Nilesh's answer is perfact, I tried to test and it works fine for me. I am also facing similar problem. Thanks Nilesh for solution.