例如我有几张桌子:
产品:
| product_id | name | price |
| 1 | apple | 20.32 |
| 2 | pear | 9.99 |
| 3 | banana | 1.5 |
产品属性:
| attr_id | name | value |
| 1 | weight | 10 kg |
| 2 | date | 2013 |
| 3 | color | red |
...等等。
最后产品属性关系表:
| product_id | attr_id |
| 1 | 3 |
| 2 | 1 |
| 1 | 2 |
| 3 | 2 |
我的问题:是否有可用的构造 ONE 选择请求查询以以下数据结构(或类似数据结构)返回产品 1 和 2?现在我应该首先运行 deveral 选择请求“where product_id IN (1, 2)”,然后通过循环选择它们的属性。
对不起英语不好:]
array(
[0] = array(
product_id = 1,
name = apple,
attributes= array(
[0] => array(
attr_id = 3,
name = color,
value = red,
),
[0] => array(
attr_id = 2,
name = date,
value = 2013,
)
),
),
[1] = array(
product_id = 2,
name = apple,
attributes= array(
[0] => array(
attr_id = 1,
name = veight,
value = 10 kg,
),
),
)
)