Search code examples
mysqlsqlmysql-error-1054

Unknown column {0} in on clause


I am doing some work on a MySQL database and completely stumped on receiving the error

1054 - Unknown column 'Puzzles.PuzzleID' in 'on clause'

Both the table and the column names exist and are correct. I just created it in Navicat's visual designer.

SELECT
`PuzzleCategories`.`PuzzleCategory`,
`Clients`.`BusinessName`,
`Puzzles`.`PuzzleNumber`
FROM
`Puzzles`
Inner Join `PuzzleCategories` ON `Puzzles`.`PuzzleCategoryID` = `PuzzleCategories`.`PuzzleCategoryID` ,
`Clients`
Inner Join `Publications` ON `Clients`.`ClientID` = `Publications`.`ClientID`
Inner Join `PublicationIssues` ON `PublicationIssues`.`PublicationID` =     `Publications`.`PublicationID`
Inner Join `PuzzleUsages` ON `PuzzleUsages`.`PuzzleID` = `Puzzles`.`PuzzleID` AND `PuzzleUsages`.`PublicationIssueID` = `PublicationIssues`.`PublicationIssueID`

Solution

  • If you're sure that the column names are right the problem may be from the order of the joins. It sounds like the joins each side of the comma are being built separately. (I'm not sure if this is likely or even possible but it's the only guess I have based on the info you give)

    The query could be restructured as:

    
    SELECT
    `PuzzleCategories`.`PuzzleCategory`,
    `Clients`.`BusinessName`,
    `Puzzles`.`PuzzleNumber`
    FROM
    `Clients`
    INNER JOIN `Publications` ON `Clients`.`ClientID` = `Publications`.`ClientID`
    INNER JOIN `PublicationIssues` ON `PublicationIssues`.`PublicationID` =   `Publications`.`PublicationID`
    INNER JOIN `PuzzleUsages` ON`PuzzleUsages`.`PublicationIssueID` = `PublicationIssues`.`PublicationIssueID`
    INNER JOIN `Puzzles` ON `Puzzles`.`PuzzleID` = `PuzzleUsages`.`PuzzleID`
    INNER JOIN `PuzzleCategories` ON `Puzzles`.`PuzzleCategoryID` = `PuzzleCategories`.`PuzzleCategoryID`
    
    

    which just reads better anyway.