How to query child to parent

  • How to query child to parent like contact to parent..and how to query master lookup relations.

    select id,lastnam,(select id,name from account where accountid=conatctid)from contact

  • Subhash

    Subhash Correct answer

    5 years ago

    This just an example on how the parent-child query works...

    Ways of writing Parent - Child Queries for Standard Objects

    Select Id, Name, (Select Id, LastName from Contacts where Lastname='Frank') from Account
    
    Select Id, LastName, Account.Name from Contact
    

    Ways of writing Parent - Child Queries for Custom Objects

    Select Id, Name, (Select Id, Name from Custom_Object2s__r) from Custom_Object1__c
    
    Select Id, Name, Custom_Object1__r.Name from Custom_Object2__c
    

    Hope this might helps...

    are you trying to query Account in subquery? without from ?

    This query is not working fine

    @Hemalatha paruchuri, That's k, I didn't understand your question either... hope you find your solution

    your first query should be `Select Id, LastName, (Select id, LastName from Contacts where LastName='ContactName' ) from Account` your where and from place need to be change

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM