1

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'
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
lolalola
  • 3,773
  • 20
  • 60
  • 96

2 Answers2

4

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
  • 811,555
  • 193
  • 1,581
  • 1,452
2

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

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68