G F

G F

  • NA
  • 44
  • 6.5k

SQL Error when attempting to create a three Table Join state

Feb 27 2020 6:36 PM
Hi,
 
I would like to create a MySQL Select Statement,using Joins to join 3 tables.
 
Currently in my Code, I have the two Table join working great:
  1. SELECT  
  2. traveldocuments.TDNumber,  
  3. traveldocuments.TDMoveStart,  
  4. traveldocuments.TD_ODR_O_Address,  
  5. traveldocuments.TD_ODR_D_Address,  
  6. approvals.ApprovalJurisdictionFee,  
  7. approvals.ApprovalPermitFee  
  8. FROM traveldocuments  
  9. Left JOIN approvals  
  10. ON (traveldocuments.Id=approvals.TDId);  
So I was doing some searching, and I can see examples from other languages (Java), that I should be able to just add on the third table, but it errors out (not in code but in the DBMS), this is what I tried to change it to:
  1. SELECT  
  2. traveldocuments.TDNumber,  
  3. traveldocuments.TDMoveStart,  
  4. traveldocuments.TD_ODR_O_Address,  
  5. traveldocuments.TD_ODR_D_Address,  
  6. approvals.ApprovalJurisdictionFee,  
  7. approvals.ApprovalPermitNowFee,  
  8. commodities.CommoditySteerUnitNumber  
  9. FROM traveldocuments  
  10. Left JOIN approvals  
  11. ON (traveldocuments.Id=approvals.TDId);  
  12. LEFT JOIN commodities  
  13. ON (traveldocuments.Id=commodities.TDId);  
The specific error is Unknown column : 'commodities.CommoditySeerUnitNumber' in 'field list'
 
I know this table and column exist, when I'm building the statement in HeidiSQL, it autocompletes the column name, and I've printed out my table columns and I can see it there.
 
I have a Foreign Key in the commodities table setup exactly the same way as the approvals table, it's almost like a parent/child setup.
 
Any suggestions would be appreciated.
 
Thank you!

Answers (3)