tags:

views:

47

answers:

2
+1  Q: 

MySQL Syntax error

What's wrong with this code?

FROM product_tag, ps_product_tags_all
LEFT JOIN users ON
users.id = product_tag.lang
LEFT JOIN images ON
images.id = ps_product_tags_all.lang

Error:

Unknown column 'product_tag.lang' in 'on clause'
+2  A: 

This is not syntax error, but structure error - you don't have "lang" column in "product_tag" table.

Tomasz Kowalczyk
This probably isn't the reason why the query is failing.
Mark Byers
+1  A: 

You are mixing implicit and explicit joins and joining in the wrong order. Try this:

SELECT *
FROM ps_product_tags_all
LEFT JOIN images ON
images.id = ps_product_tags_all.lang, product_tag
LEFT JOIN users ON
users.id = product_tag.lang
WHERE ...

Remember that explicit JOIN has higher precedence than the implicit join from using comma. To avoid this error I would recommend that you always use explicit joins:

SELECT *
FROM ps_product_tags_all
LEFT JOIN images ON images.id = ps_product_tags_all.lang
LEFT JOIN product_tag ON ...
LEFT JOIN users ON users.id = product_tag.lang
Mark Byers
good to know, i've always joined without that info and never had such problem. ;]
Tomasz Kowalczyk