SELECT attribute_value.value
FROM attribute_value
INNER JOIN attributes ON attributes.id=attribute_value.attribute_id
WHERE attributes.attribute IN (colour, size);
Run Code Online (Sandbox Code Playgroud)
我没有这样做,但我得到的错误是#1054 - 'where子句'中的未知列'颜色'
我正在尝试获取与之关联的属性的值.现在属性在"IN"子句中列出,但我想知道如何使用这样的关联数组:
Array([attributes] => Array ( [0] => Colour [1] => Size )
Run Code Online (Sandbox Code Playgroud)
表attribute_value
______________________________
| attribute_id | value |
------------------------------
| 1 | Red |
| 1 | Blue |
| 2 | Large |
Run Code Online (Sandbox Code Playgroud)
表属性
____________________
| id | attribute |
--------------------
| 1 | Colour |
| 2 | Size |
Run Code Online (Sandbox Code Playgroud)
为了澄清,将发布多个属性并仅使用这些属性,从attribute_value获取值,其中属性中的属性id等于attribute_value中的attribute_id
你有IN的问题.您应该在单引号之间使用字符串.
SELECT attribute_value.value
FROM attribute_value
INNER JOIN attributes ON attributes.id=attribute_value.attribute_id
WHERE attributes.attribute IN ('Colour', 'Size');
Run Code Online (Sandbox Code Playgroud)