c_pattle Posted December 1, 2011 Share Posted December 1, 2011 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 https://forums.phpfreaks.com/topic/252212-sql-help/ Share on other sites More sharing options...
awjudd Posted December 1, 2011 Share Posted December 1, 2011 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 https://forums.phpfreaks.com/topic/252212-sql-help/#findComment-1293049 Share on other sites More sharing options...
kickstart Posted December 1, 2011 Share Posted December 1, 2011 Hi Using decent indexes those JOINs should be fairly efficient (although I far prefer using JOINs coded as awjudd has suggested above). All the best Keith Link to comment https://forums.phpfreaks.com/topic/252212-sql-help/#findComment-1293053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.