私は MySQL のクエリに精通しているわけではなく、通常は非常に単純な JOIN しか行いません。私は osCommerce のインストールに取り組んでおり、カテゴリ ページにすべてのサブカテゴリの製品も含めたいと考えています。
select
p.products_image,
pd.products_name,
pd.products_description,
p.products_id,
p.manufacturers_id,
p.products_price,
p.products_tax_class_id,
IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price,
IF(s.status, s.specials_new_products_price, p.products_price) as final_price
from
products_description pd,
products p
left join
manufacturers m on p.manufacturers_id = m.manufacturers_id
left join
specials s on p.products_id = s.products_id,
products_to_categories p2c
where
p.products_status = '1' and
p.products_id = p2c.products_id and
pd.products_id = p2c.products_id and
pd.language_id = '1' and
(p2c.categories_id = '24' or ###.parent_id = '24')
order by pd.products_name asc
基本的に、categories テーブルもこのクエリに結合して、categories_id = p2c.categories_id の行をCategories テーブルから取得する必要があります。次に、カテゴリ テーブルから選択した行の parent_id 列を参照できます (上記の "###" を "cat" などに置き換えます)。
ただし、別の JOIN 句をどこに挿入する必要があるかについて、すべての左側の結合で混乱しています。
どんな助けでも大歓迎です。
ありがとう!