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 Almeida 12Arthur Almeida 12 

how to select 2 rows with same account?

I would like to do a select in one account that has 2 assets with status X

I tried with:
SELECT Id, AccountId FROM Asset WHERE Status = 'X' LIMIT 2

but this return 2 rows with 2 different accounts... I need it to be the same account...

how does it?
Best Answer chosen by Arthur Almeida 12
AnkaiahAnkaiah (Salesforce Developers) 
Hi Arthur,

You can use an aggregate SOQL query for this.
SELECT AccountId , count(Id) FROM Asset WHERE Status = 'X' GROUP BY AccountId HAVING Count(AccountId) > 1
If this helps, Please mark it as best answer.

Thanks!!