我正在尝试执行一个查询,在该查询中检索属性以及来自其他表的值。我遇到的问题是,它只返回order_property_values
表内匹配的结果行。我希望它返回所有结果,即使它在order_property_values
表内找不到匹配项。
这是我现在要查询的内容。
SELECT * FROM `properties` as t1
LEFT JOIN `order_property_values` AS t2
ON t1.`id` = t2.`property_id`
WHERE t1.`id`
IN (SELECT `property_id` FROM `assigned_properties`
WHERE `component_id`
IN (SELECT `component_id` FROM assigned_components
WHERE `product_id` = (SELECT `product_id`
FROM `order_items`
WHERE `id` = 1)
)
) AND t2.`order_id` = 13
此查询以我想要的方式检索所有内容,但没有空匹配的行。
IN
仅返回order_property_values
表中可能存在/可能不存在的ID。
我已经尝试过NOT IN
和IS NULL
,但似乎无法正常工作。
预先感谢您保存一天。
答案 0 :(得分:1)
SELECT * FROM `properties` as t1
LEFT JOIN `order_property_values` AS t2
ON t1.`id` = t2.`property_id` AND t2.`order_id` = 13
WHERE t1.`id`
IN (SELECT `property_id` FROM `assigned_properties`
WHERE `component_id`
IN (SELECT `component_id` FROM assigned_components
WHERE `product_id` = (SELECT `product_id`
FROM `order_items`
WHERE `id` = 1)
)
)