Jump to content

How to improve this query


needs_upgrade

Recommended Posts

hello guys, i wanted to improve my query. it works but it's slow. how can i improve it? do i need to rewrite my query or change the table design? pls feel free to criticize. thanks a lot.

 

here's the mysql code:

$sql = "SELECT product_num FROM products WHERE product_id IN 
			(
			SELECT to_product_id FROM tconversions WHERE fr_product_id IN
				(
				SELECT product_id FROM products WHERE product_num = '$product_num'
				)
			)";

 

and here are the tables' descriptions:

 

CREATE TABLE IF NOT EXISTS `products` (
  `product_id` int(5) unsigned NOT NULL AUTO_INCREMENT,
  `product_name` varchar(75) COLLATE latin1_general_ci NOT NULL,
  `product_num` varchar(6) COLLATE latin1_general_ci NOT NULL,
  `category_id` int(3) NOT NULL,
  `manufacturer_id` int(2) NOT NULL DEFAULT '0',
  `sell_price` decimal(9,2) NOT NULL DEFAULT '0.00',
  `active` int(1) NOT NULL COMMENT '1 if active, 0 if inactive',
  `lastsale` date NOT NULL,
  PRIMARY KEY (`product_id`)
) ENGINE=MyISAM

CREATE TABLE IF NOT EXISTS `tconversions` (
  `tconv_id` int(6) NOT NULL AUTO_INCREMENT,
  `fr_product_id` int(5) NOT NULL,
  `to_product_id` int(5) NOT NULL,
  `conv_units` decimal(8,2) NOT NULL,
  PRIMARY KEY (`tconv_id`)
) ENGINE=MyISAM;

 

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.