+ Start a Discussion

How to Pull the data from two tables by using soql-How to get account names for account who supply part p2.

I have two tables -
accounts                                            products
id    acct name   weight           acct_id    product #           name        status
a1    raju                  25                   a1              p1                  nut              hold
a2    john                 15                   a2              p2                  bolt             open
a3    ajay                 10                    a3              p2                  screw         open
a4    ravi                   05                   a4              p2                  cam            hold
                                                          a2              p3                  amy            hold
Vamsi KrishnaVamsi Krishna
you can use the query like this.. (replace the object & field names with what's there in your org)

Select Id, Name, Status, Account__r.Name form Product where ProductNumberField = 'p2'

you can run the query in developer console to see the results before using in your code or elsewhere..

also, refer this article for relationship queries in salesforce soql
Chandra PrakashChandra Prakash
please check below link