Jump to content

SQL Help


c_pattle

Recommended Posts

I have the following query

 

SELECT product_data.product_id, product_data.product_name, product_pricing.sales_price_inc_vat, products_to_categories.*  FROM product_data, product_pricing, products_to_categories WHERE product_data.product_id = product_pricing.product_id AND product_data.product_id = products_to_categories.product_id LIMIT 10

 

This works fine but the query takes a long time to excecute because it compares the "product_data.product_id" twice to two tables.  Is there a way to do this comparison but to speed up the execution time?

 

Thanks for any help

Link to comment
Share on other sites

Do you have indexes on either of the tables?

 

I would also suggest against using the ANSI JOINs (,) and move to using INNER JOINs because you will not be CROSS JOINing your dataset.

 

SELECT pd.product_id, pd.product_name, pp.sales_price_inc_vat, ptc.* 
FROM product_data pd
JOIN product_pricing pp ON pd.product_id = pp.product_id
JOIN products_to_categories ptc ON pp.product_id = ptc.product_id

 

~awjudd

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.