I need a table with data from the 4 tables listed below:
TBL_CONTACT /** data for contact **/
TBL_OPPORTUNITY /** data for opportunity **/
TBL_CONTACT_OPPORTUNITY /** uniqe identifiers linking opportunity and contact**/
TBL_ADDRESS /** address for contact **/
I can split the query in 2 and both parts work
/** Part 1 - this query linking CONTACT and OPPORTUNITY (using CONTACT_OPPORTUNITY) works **/
SELECT
TBL_CONTACT.FULLNAME,
TBL_CONTACT.COMPANYNAME,
TBL_OPPORTUNITY.NAME
FROM
TBL_CONTACT INNER JOIN TBL_CONTACT_OPPORTUNITY
ON TBL_CONTACT.CONTACTID = TBL_CONTACT_OPPORTUNITY.CONTACTID
INNER JOIN TBL_OPPORTUNITY
ON TBL_CONTACT_OPPORTUNITY.OPPORTUNITYID = TBL_OPPORTUNITY.OPPORTUNITYID
/** Part 2 - this query linking CONTACT and ADDRESS works **/
SELECT
TBL_CONTACT.FULLNAME,
TBL_CONTACT.COMPANYNAME,
TBL_ADDRESS.LINE1,
TBL_ADDRESS.CITY,
TBL_ADDRESS.STATE
FROM
TBL_CONTACT INNER JOIN TBL_ADDRESS
ON TBL_ADDRESS.CONTACTID = TBL_CONTACT.CONTACTID
The combined query as designed with Design Query Editor displays no records. I can see that TBL_CONTACT needs to be joined seperately to TBL_ADDRESS and TBL_CONTACT_OPPORTUNITY but I don’t know how to do it. Any ideas would be greatly appreciated.
/** Combined query returns no records **/
SELECT
TBL_CONTACT.FULLNAME,
TBL_CONTACT.COMPANYNAME,
TBL_OPPORTUNITY.NAME,
TBL_ADDRESS.LINE1,
TBL_ADDRESS.CITY,
TBL_ADDRESS.STATE
FROM
TBL_CONTACT INNER JOIN TBL_ADDRESS
ON TBL_ADDRESS.CONTACTID = TBL_CONTACT.CONTACTID INNER JOIN
TBL_CONTACT_OPPORTUNITY
ON TBL_CONTACT.CONTACTID = TBL_CONTACT_OPPORTUNITY.CONTACTID INNER JOIN
TBL_OPPORTUNITY
ON TBL_ADDRESS.OPPORTUNITYID = TBL_OPPORTUNITY.OPPORTUNITYID AND
TBL_CONTACT_OPPORTUNITY.OPPORTUNITYID = TBL_OPPORTUNITY.OPPORTUNITYID