+ Start a Discussion

How to write a select query using two tables and compare two id's?

Hi All,


I am working on salesforce to java integration through webservices


How to write a select query using two tables like QuoteLineItem and PricebookEntry and compare id's  and get the product2id . this query how to write ?


i write a query like this 


QueryResult q = binding.query("select id,(select id,product2id from PricebookEntry)from QuoteLineItem");


i am getting errors


faultCode: {urn:fault.enterprise.soap.sforce.com}INVALID_TYPE
faultString: INVALID_TYPE:
id,(select id,product2id from PricebookEntry)from QuoteLineItem
ERROR at Row:1:Column:38
Didn't understand relationship 'PricebookEntry' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
id,(select id,product2id from PricebookEntry)from QuoteLineItem


plz help..




Use as following....


select id,PricebookEntry.product2id from QuoteLineItem



Hi Varun,


ok ,I need to compare both object id's PricebookEntry object id and QuoteLineItem object PricebookEntryId


like this  PricebookEntry.id = QuoteLineItem.PricebookEntryId  if both id's same get the product2Id


How to write single sql query?


plz need help...


Hi Devi,


 To accomplish this u need to write the query using INNERJOIN. Try the following: 


SELECT PricebookEntry.id,PricebookEntry.product2id FROM QuoteLineItem INNER JOIN PricebookEntry ON QuoteLineItem.Id=PricebookEntry.Id


I hope this will helpful for you.