私の(非常に単純化された)スキーマには、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はうまく機能します。
選択サブクエリで派生テーブルattrを使用する方法はありますか?
あるので、別のクエリでそれをやろうVALUE_ID 。エイリアス名 'attr'を内部結合クエリの他の名前に変更します。 – Bajrang