这是我的产品表:
CREATE TABLE `products` (
`idproduct` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`description` text NOT NULL,
`price` double unsigned NOT NULL,
`shipping` double unsigned DEFAULT NULL,
`condition` int(10) unsigned NOT NULL,
`returns` int(10) unsigned NOT NULL,
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`image` varchar(255) DEFAULT NULL,
PRIMARY KEY (`idproduct`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8
这是我的product_categories表
CREATE TABLE `products_subcategories` (
`idproduct_category` int(10) unsigned NOT NULL AUTO_INCREMENT,
`idproduct` int(10) unsigned NOT NULL,
`idsubcategory` int(10) unsigned NOT NULL,
PRIMARY KEY (`idproduct_category`),
KEY `products_categories_products_idx` (`idproduct`),
KEY `products_categories_categories_idx` (`idsubcategory`),
CONSTRAINT `products_subcategories_products` FOREIGN KEY (`idproduct`) REFERENCES `products` (`idproduct`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `products_subcategories_subcategories` FOREIGN KEY (`idsubcategory`) REFERENCES `subcategories` (`idSubcategory`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
我试图搜索这样的产品:
Select products.* from products
INNER JOIN products_subcategories
ON products.idproduct = products_subcategories.idproduct
WHERE name LIKE '%p%'
但它只返回一行..没有内连接它会返回更多行