mysqljoin

How do i reference a column in a join?


I was expecting the join to replace the ID 8n document table with the DocType.TypeName

This query yields 1 row as expected

SELECT * FROM `DocType` WHERE `ID`            
=1 

ID TypeName 
1  PDF

This query using join

SELECT            
    *            
FROM            
    Document            
LEFT JOIN(DocType) ON (            
        Doctype.ID = Document.DocType           
)

Gives an error #1054 - Unknown column 'Doctype.ID' in 'on clause'

The first query shows DocType.ID is a valid column... Is there a different way to represent a column other than table.column?


Solution

  • You need to write the SQL query in the correct syntax. Remove the parentheses and add as follows and the problem will be solved.

    SELECT  *  FROM  Document  LEFT JOIN DocType ON  DocType.ID = Document.DocType;