Inner query in soql can only happen for master-detail relationship or also for lookup relationship?
Inner query in case of master detail as below :
SELECT ID, (SELECT Amount FROM Opportunity) FROM Account;
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
Works for lookup relationship as well. The reason the above query is not working is because you need to use plural form of Opportunity.
You can do on both master-detail and lookup relationships. When writing an inner query you need to use the Child Relationship name of the master-detail/lookup relationship. For standard objects it's typically the plural name of the child object as per Lance's answer, however for custom relationships you define the Child Relationship name when you create the relationship and you need to always append
__r at the end:
[SELECT Id, (SELECT Id FROM MyCustomObject__r) FROM Account]