Jump to content

[SOLVED] same qry, same db


scottybwoy

Recommended Posts

Hi all,

 

I have a duplicate of the same db on my test server as my live server and am running exactly the same query on both but the one on my test server fails but the live one works fine.

 

Here's the qry :

 SELECT p.products_id, p.products_image, p.products_tax_class_id, if( s.status, s.specials_new_products_price, p.products_price ) AS products_price
FROM products p, products_description pd, products_to_categories p2c, categories c
LEFT JOIN specials s ON p.products_id = s.products_id
WHERE products_status = '1'
AND p.products_ordered >0
AND p.products_id = pd.products_id
AND pd.language_id = '1'
AND p.products_id = p2c.products_id
AND p2c.categories_id = c.categories_id
AND '0'
IN (
c.categories_id, c.parent_id
)
ORDER BY p.products_ordered DESC
LIMIT 10 

 

The error I'm getting on my test server is :

 

#1054 - Unknown column 'p.products_id' in 'on clause'

 

But I know that column is there.  My test server is running MySQL 5.0.20-nt and my Live server is running v.4.1.22-max-log

Link to comment
Share on other sites

No, it's because the comma operator and JOIN don't have the same precedence in v5.

 

Moral of the story -- NEVER EVER EVER use the comma operator -- EVER.  It's only 3 extra characters to do it properly.

 

In the meanwhile, wrapping the "comma-separated" list of tables in parens will "solve" your problem -- see below.

 

SELECT p.products_id, p.products_image, p.products_tax_class_id, if( s.status, s.specials_new_products_price, p.products_price ) AS products_price
FROM (products p, products_description pd, products_to_categories p2c, categories c)
LEFT JOIN specials s ON p.products_id = s.products_id
WHERE products_status = '1'
AND p.products_ordered >0
AND p.products_id = pd.products_id
AND pd.language_id = '1'
AND p.products_id = p2c.products_id
AND p2c.categories_id = c.categories_id
AND '0'
IN (
c.categories_id, c.parent_id
)
ORDER BY p.products_ordered DESC
LIMIT 10 

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.