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
Harikishore BandiHarikishore Bandi 

How to retrive Opportunity name and Account name where Opportunities are related with Accounts .

Hello:
SELECT Name FROM Opportunity WHERE AccountId IN (SELECT Id FROM Account);

Why its throwing error while I'm including field Account in below query when i was trying to retrive Opportunity name and Account name.

SELECT Name, Account FROM Opportunity WHERE AccountId IN (SELECT Id FROM Account);

This column details are related to Opportunity name.I want to retrieve related Account names for that oppurtunity name.
Ujwala Mane 17Ujwala Mane 17
Hi,
replace Account with Accountid 

SELECT Name, Accountid FROM Opportunity WHERE AccountId IN (SELECT Id FROM Account)

 
Harikishore BandiHarikishore Bandi
@Ujwala Mane17
Thanks for your reply,
But actually what i needed was not AccountID but the Name of the Account with Which Opportunity is related. For example Consider a unit in Account as "abcAccount" and related Opportunities as i) Opp1 and  ii) Opp2. The thing I'm expecting was the output should display as

Name                                                                      Account Name
----------------------------------------------------------------------------------------------
Opp1                                                                        abcAccount
Opp2                                                                        abcAccount
 
SarvaniSarvani
Hi Harikishore,

Try this:
SELECT Name,Account.name FROM Opportunity WHERE AccountId IN (SELECT Id FROM Account)

Hope this helps, Mark as best if it does.

Thanks