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
NielsenPeterNielsenPeter 

Help with how to combine 2 simple SOQL queries

Im still learning SOQL and want to figure out how to merge the bottom query into the top ,so that I only show cases that created in the last 365 days, rather than all the cases for that account.

SELECT Name, ID,
(SELECT Name, Amount FROM Opportunities),
(SELECT Reason, COUNT(ID) FROM Cases),
(SELECT Id, LastName, Email FROM Contacts)
FROM Account
Where ID = '{pv0}'
ORDER BY Name ASC
************************
SELECT Reason, COUNT(ID)
FROM Case
WHERE AccountId = '{pv0}'
AND Case.CreatedDate = LAST_N_DAYS:365
GROUP BY Reason
************************************
Thank you 
NielsenPeterNielsenPeter
I thought something like this would work but its wrong somehow.


SELECT Name, ID,
(SELECT Name, Amount FROM Opportunities),

(SELECT Reason, COUNT(ID) 
FROM Cases
WHERE AccountId = '{pv0}'
AND Case.CreatedDate = LAST_N_DAYS:365
GROUP BY Reason),

(SELECT Id, LastName, Email FROM Contacts)
FROM Account
Where ID = '{pv0}'