We help IT Professionals succeed at work.
Get Started

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

G F
G F asked
on
175 Views
Last Modified: 2020-02-28
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
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 20 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE