Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QUERY:
- SELECT orders_products.order_id FROM orders_products INNER JOIN orders ON orders.id = orders_products.order_id WHERE orders_products.productcode = 26232 AND orders.paid = 1;
- EXPLAIN:
- +----+-------------+-----------------+------+--------------------+--------+---------+------------------------+-------+-------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-----------------+------+--------------------+--------+---------+------------------------+-------+-------------+
- | 1 | SIMPLE | orders | ALL | PRIMARY | NULL | NULL | NULL | 24983 | Using where |
- | 1 | SIMPLE | orders_products | ref | Search,productcode | Search | 3 | mydatabase.orders.id | 1 | Using where |
- +----+-------------+-----------------+------+--------------------+--------+---------+------------------------+-------+-------------+
- SHOW CREATE TABLE orders:
- CREATE TABLE `orders` (
- `id` mediumint(7) unsigned NOT NULL AUTO_INCREMENT,
- `status` tinyint(1) unsigned NOT NULL DEFAULT '0',
- `client_name` varchar(50) NOT NULL DEFAULT '',
- `client_vatnumber` varchar(16) DEFAULT NULL,
- `client_address1` varchar(100) NOT NULL DEFAULT '',
- `client_address2` varchar(50) NOT NULL DEFAULT '',
- `client_email` varchar(80) NOT NULL DEFAULT '',
- `client_phone` varchar(30) NOT NULL DEFAULT '',
- `client_birthday` date DEFAULT NULL,
- `referencenumber` varchar(20) NOT NULL DEFAULT '',
- `info` text,
- `totalprice` decimal(9,2) NOT NULL DEFAULT '0.00',
- `added` datetime NOT NULL,
- `paid` tinyint(1) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `Search` (`status`,`client_email`,`referencenumber`,`totalprice`),
- KEY `client_name` (`client_name`)
- ) ENGINE=MyISAM AUTO_INCREMENT=47974 DEFAULT CHARSET=latin1
- SHOW CREATE TABLE orders_products:
- CREATE TABLE `orders_products` (
- `ProductOrderID` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `order_id` mediumint(7) unsigned NOT NULL DEFAULT '0',
- `count` tinyint(1) NOT NULL DEFAULT '0',
- `productcode` varchar(10) NOT NULL DEFAULT '',
- `prodtype` tinyint(3) unsigned NOT NULL DEFAULT '0',
- `name` varchar(80) NOT NULL DEFAULT '',
- `price` decimal(9,2) NOT NULL DEFAULT '0.00',
- `ProductReleaseDate` date DEFAULT '0000-00-00',
- PRIMARY KEY (`ProductOrderID`),
- KEY `Search` (`order_id`,`price`,`name`),
- KEY `productcode` (`productcode`),
- ) ENGINE=MyISAM AUTO_INCREMENT=61460 DEFAULT CHARSET=latin1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement