Search code examples
mysqlmysql-workbenchmysql-error-1064

Error 1064 for no apparently reason


I got this query:

SELECT  companies_comments.id as id, 
        companies_comments.post as post, 
        companies_comments.comment as comment, 
        companies_comments.date as date, 
        companies.`id` AS company, 
        companies.`name` as name, 
        companies.`username` as username, 
        companies.`photo` as photo, 
        companies.`status` AS company_status
LEFT JOIN companies ON companies.id = companies_comments.company
WHERE company_status NOT IN (3,4)
AND companies_comments.post =1

The error: Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN companies ON companies.id = companies_comments.company WHERE compa' at line 10

Error 1064 unexpectedly. Just tried with no ` , same results. No missing column. What can be happening?


Solution

  • You're missing the tablename and also a FROM section in the query

    SELECT  companies_comments.id as id, 
            companies_comments.post as post, 
            companies_comments.comment as comment, 
            companies_comments.date as date, 
            companies.`id` AS company, 
            companies.`name` as name, 
            companies.`username` as username, 
            companies.`photo` as photo, 
            companies.`status` AS company_status
    FROM companies, companies_comments
    LEFT JOIN companies ON companies.id = companies_comments.company
    WHERE companies.company_status NOT IN (3,4)
    AND companies_comments.post =1