我不是那麼熟悉MySQL查詢,我通常只做非常簡單的JOIN。我正在安裝osCommerce,我希望類別頁面也包含所有子類別的產品。加入一個表到一個對我來說太複雜的SQL查詢
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_id = p2c.categories_id拉動行。然後,我可以從類別表中選擇的行中引用parent_id列(我會用「cat」替代上面的「###」)。
但是,我對所有左連接感到困惑,應該在哪裏插入另一個JOIN子句。
任何幫助將不勝感激。
謝謝!
。 。如果您格式化查詢,您可能會發現修改和維護起來要容易得多。 –
我這樣做。 osCommerce喜歡把它們扔在真正荒謬的長線上。 –
那裏。我在我的問題中重新格式化了示例查詢。 –