Jump to content

[SOLVED] Unknown column error when column exists


anatak

Recommended Posts

Hello,

 

I am totally at a loss here.

I have a query

 

SELECT content_cat_m2m_sub_cat.CategoryId as CatId, content_category.Lan_1 as CatLan_1, content_cat_m2m_sub_cat.SubCategoryId as SubCatId, content_sub_category.Lan_1 as SubCatLan_1, content_sub_cat_m2m_element.ElementId, content_element.Lan_1 as Element_1 FROM content_cat_m2m_sub_cat, content_sub_cat_m2m_element LEFT JOIN content_category ON content_cat_m2m_sub_cat.CategoryId = content_category.Id LEFT JOIN content_sub_category ON content_cat_m2m_sub_cat.SubCategoryId = content_sub_category.Id LEFT JOIN content_element ON content_sub_cat_m2m_element.ElementId = content_element.Id WHERE content_cat_m2m_sub_cat.SubCategoryId = content_sub_cat_m2m_element.SubCategoryId ORDER BY CatLan_1, SubCatLan_1, Element_1 ASC ;

 

that works on my local (my pc) database but gives an error on my webserver database (the tables are exported from local to webserver) so that is already something I don't understand.

 

the error I get is

#1054 - Unknown column 'content_cat_m2m_sub_cat.CategoryId' in 'on clause'

in this line

LEFT JOIN content_category ON content_cat_m2m_sub_cat.CategoryId = content_category.Id

 

When I run this query I don't get the error ( it has the same on close)

 

SELECT content_cat_m2m_sub_cat.CategoryId as CatId, content_category.Lan_1 as CatLan_1, content_cat_m2m_sub_cat.SubCategoryId as SubCatId, content_sub_category.Lan_1 as SubCatLan_1

FROM content_cat_m2m_sub_cat

LEFT JOIN content_category ON content_cat_m2m_sub_cat.CategoryId = content_category.Id

LEFT JOIN content_sub_category ON content_cat_m2m_sub_cat.SubCategoryId = content_sub_category.Id

ORDER BY CatLan_1, SubCatLan_1 ASC ;

 

Can anyone offer some advice ?

 

anatak

Link to comment
Share on other sites

My guess is that the one that doesn't work runs on MySQL 5 -- the precedence rules for the comma operator have changed.  Try:

 

SELECT content_cat_m2m_sub_cat.CategoryId as CatId, content_category.Lan_1 as CatLan_1, content_cat_m2m_sub_cat.SubCategoryId as SubCatId, content_sub_category.Lan_1 as SubCatLan_1, content_sub_cat_m2m_element.ElementId, content_element.Lan_1 as Element_1 FROM (content_cat_m2m_sub_cat, content_sub_cat_m2m_element) LEFT JOIN content_category ON content_cat_m2m_sub_cat.CategoryId = content_category.Id LEFT JOIN content_sub_category ON content_cat_m2m_sub_cat.SubCategoryId = content_sub_category.Id LEFT JOIN content_element ON content_sub_cat_m2m_element.ElementId = content_element.Id WHERE content_cat_m2m_sub_cat.SubCategoryId = content_sub_cat_m2m_element.SubCategoryId ORDER BY CatLan_1, SubCatLan_1, Element_1 ASC ;

Link to comment
Share on other sites

http://dev.mysql.com/doc/refman/5.0/en/join.html

 

Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.