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
mathan kumarmathan kumar 

this is valid or invalid query SELECT AccountFeed.Id, Account.Id FROM ( Account INNER JOIN AccountFeed ON Account.Id = AccountFeed.Id)

Best Answer chosen by mathan kumar
Chellappa NagarajanChellappa Nagarajan

Hi Mathan,
You don't have to mention specifically the keywords 'INNER JOIN' in SOQL as compared to SQL in other database languages.
Please look at below two ways of Inner Joins. 

Right Inner Join - Look Up Parent field Values - No Orphans.
List<AccountFeed> listAccFeed = [select Parent.ID,Parent.Name, Id from AccountFeed where ParentId <> null and Parent.Type = 'Prospect'];

Left  Inner Join - LookUp Children Values no childless parent
Query - List<Account> listAcc = [select Id, (select Parent.ID,Parent.Name, Id from Account.Feeds) from Account 
where Id in (select ParentId from AccountFeed where ParentId <> null )];

You can use the below article for more understanding. I used the same. Hope this helps now.
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com

Thanks,
Chellappa

All Answers

VamsiVamsi
Hi,

Its invalid. Please let me know, what you would like to retrieve and from where 
Chellappa NagarajanChellappa Nagarajan
Hi Mathan,

If i understand your query correctly, you are trying to retrieve AccountFeed for a list of accounts. If so, here is the query you can use...

List<Account> listAcc = [select Account.id, (select AccountFeed.id from Account.Feeds) from Account where id in :ids];
//ids is just a variable i used for holding the list of Account ID.
The single relationship query will give AccountFeed records for Accounts given in the parameters.

I hope this is what you are looking for.

Thanks,
Chellappa
 
mathan kumarmathan kumar
how to make inner join.pls give some idea.
Chellappa NagarajanChellappa Nagarajan

Hi Mathan,
You don't have to mention specifically the keywords 'INNER JOIN' in SOQL as compared to SQL in other database languages.
Please look at below two ways of Inner Joins. 

Right Inner Join - Look Up Parent field Values - No Orphans.
List<AccountFeed> listAccFeed = [select Parent.ID,Parent.Name, Id from AccountFeed where ParentId <> null and Parent.Type = 'Prospect'];

Left  Inner Join - LookUp Children Values no childless parent
Query - List<Account> listAcc = [select Id, (select Parent.ID,Parent.Name, Id from Account.Feeds) from Account 
where Id in (select ParentId from AccountFeed where ParentId <> null )];

You can use the below article for more understanding. I used the same. Hope this helps now.
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com

Thanks,
Chellappa

This was selected as the best answer