troubleshooting Question

Issue with SQL join with 4 tables, where one is a parent Table

Avatar of G F
G FFlag for Canada asked on
MySQL ServerSQL
20 Comments1 Solution180 ViewsLast Modified:
I'm using SQL joins from three child tables, to form one table, and that works fine.
However, I would like to pull the name of a customer from a table that is a parent, in the same SQL statement.

Here is the code to my working Three Table Join:

SELECT

traveldocuments.TDNumber,
traveldocuments.TDMoveStart,
traveldocuments.TD_ODR_O_Address,
traveldocuments.TD_ODR_D_Address,
approvals.ApprovalJurisdictionFee,
approvals.ApprovalPermitNowFee,
commodities.CommoditySteerUnitNumber,
commodities.CommodityName

FROM traveldocuments
LEFT JOIN approvals ON (traveldocuments.Id=approvals.TDId)
LEFT JOIN commodities ON (traveldocuments.Id=commodities.TDId);




I tried adding the field: customers.CustomerName, and another Join:  LEFT JOIN customers ON (traveldocuments.ID=customers.ID);

But all I get are NULL values in the Joined Column, instead of the Customer Names.

So I'm not sure how to get the Name of the Customer, corresponding to the TDId.  With the other tables, approvals and commodities, they are child tables, but the now the Customers is a parent Table to traveldocuments.

Any help would be appreciated.

Thank you!
G
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 20 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros