I need to retrieve an object's info from a single query. Lets say I have 4 objects (A__c, B__c, C__c, D__c). The relationship is that B__c has the master-detail relationship with A__c and B__c is also the child of C__c (lookup relationship). D__c is the child of C__c (Master-detail relationship on D__c).
Now I need to run a query on A__c to get the related details of D__c. I could take out the info till C__c but dont know how to move after that. Please help. Below is the query I have tried:
SELECT (Select ID, Name, C__r.Name FROM B__r)ID, Name from A__c