在我的(非常简化的)模式中,我有3个表格:offer,attributes,attributes_offers。Mysql:在子查询中使用派生表
我想使用子查询从一个派生表,在此查询:
SELECT
o.offer_id,
GROUP_CONCAT(CONCAT(attr.attribute_code,'-',attr.value_id,'-',attr.value_value) SEPARATOR ';') AS attributes,
(SELECT attr.value_id FROM attr WHERE attribute_code = 'area') AS area_id,
(SELECT attr.value_id FROM attr WHERE attribute_code = 'category') AS category_id
FROM offers o
INNER JOIN (
SELECT offer_id,attribute_code,value_id,value_value
FROM attributes_offers ao
INNER JOIN attributes att USING (attribute_code)
) AS attr ON attr.offer_id = o.offer_id
然而MySQL回答我:Table 'attr' doesn't exist
。
Group_concat效果很好。
有没有办法在select子查询中使用我的派生表attr?
做出不同的别名为表'attr' 。并将别名“attr”更改为任何其他内部联接查询的名称。 – Bajrang 2012-02-28 10:13:20