Search code examples
mysqlmysql-error-1064natural-join

What the Heck is wrong with my (not to complex) MySQL-Query?


I might be blind on both eyes, but iterating through a lot of versions and tries... Deleted the hyphenation and the AS statements...

I always ended up with a parsing Error 1064 from my MySql5.1 Server. I really believe this is valid, SQL Answers:

Are there any suggestions?

SELECT (dpa_articles.name, [...] corporations.isin) FROM corporations 
NATURAL JOIN corporations_dpa_articles ON (corporations.id = corporations_dpa_articles.corporation_id)
NATURAL JOIN dpa_articles ON (dpa_articles.id = corporations_dpa_articles.dpa_article_id)
NATURAL JOIN dpa_articles_dpa_categories ON (dpa_articles.id = dpa_articles_dpa_categories.dpa_article_id)
WHERE dpa_articles_dpa_categories.dpa_category_id = 28

#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 'ON (corporations.id=corporations_dpa_articles.corporation_id) NATURAL JOIN dpa_a' at line 3

Thank you very much in advance.


Solution

  • NATURAL JOIN should not have an ON clause.

    The joining condition is implicit and based on column names.

    You need INNER JOIN as the column names are different. id will not natural join to corporation_id