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
hchhch 

Error: duplicate alias: Name in AggregateResult

Hi,

 

I am trying to retrieve the list of users grouping by their role names:

The output should be something like:

 

Role A

   User A

   User B

Role B

   User C

   User D

 

I used the following query:

list<AggregateResult> listAr  = [select  UserRole.Name,name from User where  IsActive =true group by UserRole.Name];

 

but it is showing the duplicate alias: Name error.

 

How can I achieve this?

 

Thanks in advance!!

 

 

apex_keenapex_keen

'Group by' is used when you have to perform operations like sum, min max on some field and result being grouped based on  your 'group by' field . I dont think, your query is valid.

If you want to show result  in VF page that you can try what is mentioned in the following post . This post states different problem but achieve what you have mentioned.

 

http://blog.jeffdouglas.com/2011/03/02/dynamically-group-display-query-results/

 

Thanks !

hchhch

I referred to that blog,

 

But, I want to display the Role name only once.And  the o/p Should be like:

 

ROLE A

   User A

   User B

iBr0theriBr0ther

RE:

 

 [select  UserRole.Name,name from User where .....

 

AggregateResult found double name in it. just make those different by alias:

 

 [select  UserRole.Name,name name2 from User where .....

 

Hope this help.