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
Arthur Santos AlmeidaArthur Santos Almeida 

The equivalent of "distinct" in SOQL does not work

I need to run a query but do not must return account id duplicated.

I followed these articles:
  • https://developer.salesforce.com/forums/?id=906F00000008yzrIAA
  • https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_groupby.htm
and this is my query: 
SELECT Id, AccountId FROM Asset GROUP BY AccountId

but this gives an error: 
[MALFORMED_QUERY] Field must be grouped or aggregated: Id

what do I need to change in my query to she works?
Best Answer chosen by Arthur Santos Almeida
Arthur Santos AlmeidaArthur Santos Almeida
Jigar Patel 31 and mukesh gupta thank you for your answer, it all works but I need Id Asset too, this works: 
SELECT Max(Id), AccountId FROM Asset GROUP BY AccountId
 

All Answers

Jigar Patel 31Jigar Patel 31
You have to remove id from selection since id is unique key which not allow you to select unique accountid. 
please try SELECT AccountId FROM Asset GROUP BY AccountId
 
mukesh guptamukesh gupta
Hi Arthur,

Please use below line:-
 
SELECT  AccountId, COUNT(Id) FROM Asset GROUP BY AccountId
if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
Arthur Santos AlmeidaArthur Santos Almeida
Jigar Patel 31 and mukesh gupta thank you for your answer, it all works but I need Id Asset too, this works: 
SELECT Max(Id), AccountId FROM Asset GROUP BY AccountId
 
This was selected as the best answer
Carry AdamsCarry Adams
What is it about the market that motivates prestigious firms like Accenture, IBM, Deloitte, and others to depend on Johannesburg-based software development companies (more about you can find here https://mobilunity.com/blog/software-development-services-south-africa/)? In this article, we will examine the advantages and drawbacks of working with a local workforce in South Africa in order to assist team managers in determining whether it is the best location for their requirements.