【发布时间】:2013-11-22 16:40:59
【问题描述】:
昨天我遇到了一个问题:
High availability Search implementation in PHP+MySQL
实施melc的解决方案后,我需要更改我的查询,我遇到了这个问题:
所以我有:
product:
id int(10) unsigned not null primary key auto_increment
name varchar(200),
price float(5,2),
type int(10)
attribute:
id int(10)
name varchar(100) /*e.g. red, small, large, green, metal, plastic etc...*/
product_attribute:
attribute_id int(10)
product_id int(10)
所以我在“属性”表中拥有所有自定义属性,例如颜色、尺寸、金属/塑料类型等。到目前为止,我有超过 500 和 50 种类型(大小、颜色、形状等...)
所以,如果我想获得我做的所有红色产品:
select * from product_attribute
where attribute_id = 4 (for reg)
现在,如果我想要所有与此匹配的产品:红色和蓝色、小号、塑料
我试着做:
select * from product_attribute
where attribute_id = 4 and attribute_id = 5 and attribute_id = 10 and attribute_id = 38
但这没有返回,所以我尝试了:
select * from product_attribute
where attribute_id = 4 OR attribute_id = 5 OR attribute_id = 10 OR attribute_id = 38
但后来我得到的属性与我想要的不对应!
我能做什么?我的数据库表错了吗?
【问题讨论】:
标签: mysql sql database-design