【发布时间】:2014-01-20 17:20:43
【问题描述】:
SELECT attribute_value.value
FROM attribute_value
INNER JOIN attributes ON attributes.id=attribute_value.attribute_id
WHERE attributes.attribute IN (colour, size);
我做的不对,但我得到的错误是 #1054 - 'where 子句'中的未知列 'Colour'
我正在尝试获取与之关联的属性的值。现在属性在“IN”子句中列出,但我想知道如何使用这样的关联数组:
Array([attributes] => Array ( [0] => Colour [1] => Size )
表属性值
______________________________
| attribute_id | value |
------------------------------
| 1 | Red |
| 1 | Blue |
| 2 | Large |
表格属性
____________________
| id | attribute |
--------------------
| 1 | Colour |
| 2 | Size |
为了澄清,将发布多个属性并仅使用这些属性,从属性值中获取值,其中属性中的属性 id 等于属性值中的属性 ID
【问题讨论】:
-
试试这个
attributes.attribute IN ('colour', 'size')。 -
colour和size确实是字符串常量。没有引号,mysql会将它们解释为字段名。