You need to sign in to do that
Don't have an account?

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!!
'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 !
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
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.