我尝试使此查询包含所有products_options_name结果,即使信息表中没有所选语言的相关行也是如此。 当我现在运行查询时,只显示products_propoptions,其中包含信息表中所选语言的相关行。
非常感谢任何帮助。 提前致谢, BAS
SELECT PPO.products_options_name, I.information_title, PTL.information_id,
COUNT(PPA.products_attributes_id) as amount,
options_id FROM products_propattributes PPA
INNER JOIN products_propoptions PPO ON PPA.options_id = PPO.products_options_id
LEFT JOIN properties_to_information PTL ON PPA.options_id = PTL.option_id
LEFT JOIN information I ON PTL.information_id = I.information_id
WHERE PPO.language_id = 6 AND I.language_id = 6 AND PPA.products_id = 121
GROUP BY PPA.options_id ORDER BY PPA.products_options_sort_order
表:products_propoptions
表:products_propattributes
表:信息
表:properties_to_information
答案 0 :(得分:0)
您是否尝试将INNER JOIN更改为LEFT JOIN? INNER JOIN可能导致查询省略您正在寻找的结果集行。
答案 1 :(得分:0)
这修好了.. 包含LEFT OUTER JOINS以及连接中的where条件... 谢谢.. BAS
SELECT
PPO.products_options_name,
PTL.lexicon_id,
I.information_title,
COUNT(PPA.products_attributes_id) as amount,
options_id
FROM products_propattributes PPA
LEFT OUTER JOIN products_propoptions PPO ON PPA.options_id = PPO.products_options_id AND PPO.language_id = 6
LEFT OUTER JOIN properties_to_information PTL ON PPA.options_id = PTL.option_id
LEFT OUTER JOIN information I ON PTL.lexicon_id = I.information_id AND I.language_id = 6
WHERE PPA.products_id = 121
GROUP BY PPA.options_id ORDER BY PPA.products_options_sort_order