first time I have needed to do a join in soql and I'm lost.

in MySQL it would be

Select  AccountId,  Account.ParentId,  Account.Dealer_ID__c, User.Name 
FROM Account
LEFT JOIN User on (account.OwnerId = User.id)

but I can't make it work salesforce, the closest I have that works is:

FROM User 
Where Id IN (SELECT OwnerId FROM Account where Dealer_ID__c = '04932')

but that works only for a single id, not for getting all rows from Account.


If you are joining on account.ownerId then

select name, owner.email, owner.firstname, owner.lastname from Account where ...

will join the Account to its owner User record

|improve this answer|||||
  • well ok, I was making it far to hard on my self. I will come back when I get a rep of 15 to upvote ;-) – KiwiFool Jul 16 '14 at 21:34
  • no problem, while you're at it, it is worthwhile knowing about parent->child relationship queries as in select name, (select id, name, amount from Opportunities) from Account where ... – cropredy Jul 16 '14 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.