我有一个名为product_data
的主表,它链接到另一个名为attrib_category
的表。
attrib_category
表包含字段id
,name
,subcat
。每条记录都有一个id
和name
,但有些记录没有为subcat
设置值,我注意到当我加入attrib_category
的记录时没有prouct_data
值设置的subcat
会抛出处理该记录的错误。
SELECT
product_data.*,
attrib_categorymain.id AS attrib_categorymain_id,
attrib_categorymain.name AS attrib_categorymain_name,
attrib_categorymain.subcat AS subcat
FROM product_data
LEFT JOIN attrib_categorymain ON attrib_categorymain.id = product_data.attrib_categorymain
答案 0 :(得分:0)
试试这个
SELECT product_data.*,
attrib_categorymain.id AS attrib_categorymain_id,
attrib_categorymain.name AS attrib_categorymain_name,
attrib_categorymain.subcat AS subcat
FROM product_data product_data
LEFT JOIN attrib_category attrib_categorymain
ON attrib_categorymain.id = product_data.attrib_categorymain