0

I have two objects named as 'Opportunity' and 'Account. I need to select ID, OpportunityName,CreatedDate from Opportunity table and AccountName, AccountCat from Account table where Account.OpportunityID = Opportunity.ID and AccountCat = 'DC'.

I refer this tutorial and executed in workbench, but didn't work.

Following is the query I used.

SELECT AccountName, AccountCat (SELECT Id, OpportunityName,CreatedDate FROM Opportunity) FROM Account WHERE OpportunityID 
IN (SELECT Id FROM Opportunity) AND AccountCat = 'DC'
Chanuka Ranaba
  • 635
  • 3
  • 12
  • 24

1 Answers1

2

Run your query on the Opportunity object and then use reference fields to select fields from the parent object.

SELECT  Id
    ,   Name
    ,   CreatedDate
    ,   Account.Name
FROM    Opportunity
WHERE   Account.Name = 'GenePoint'

AccountCat is not a standard field, so I assume it's a custom field, in which case you need to use the developer name, probably something like Account.Cat__c or Account.Category__c or something like that.

SOQL is superficially similar to SQL, but there are significant differences, one of them being how records are joined.

JDB
  • 25,172
  • 5
  • 72
  • 123