Home > Software design >  Joining tables on two columns
Joining tables on two columns

Time:04-09

How do I join these two tables on ServiceContract and LogicalAdress? When I try LEFT JOIN I end up with way more rows than there initially are.

https://www.db-fiddle.com/f/a8ZiSmfx8iTMe4kwEtfSsb/1

I've tried the query below but it gives me "Query Error: Error: ER_BAD_FIELD_ERROR: Unknown column 'ServiceContract' in 'from clause'".

SELECT * 
FROM `ServiceErrorsProd`
JOIN `ServiceProductions` USING (ServiceContract, LogicalAdress)

CodePudding user response:

The error reported by that query is actually:

Query Error: Error: ER_BAD_FIELD_ERROR: Unknown column 'a.LogicalAdress' in 'on clause'

This line:

`LogicalAdress ` varchar(53) DEFAULT NULL,
              ^ extra space

Should be:

`LogicalAdress` varchar(53) DEFAULT NULL,

Delimited identifiers allows you to have identifiers with characters normally not allowed, including whitespace.

  • Related