我正在尝试执行一个查询,在该查询中检索属性以及来自不同表的值。我遇到的问题是它只返回与 order_property_values
内匹配的结果行 table 。我希望它返回所有结果,即使它在 order_property_values
中找不到匹配项。 table 。
这是我现在的查询。
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
但似乎无法发挥作用。
预先感谢您挽救了这一天。
最佳答案
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)
)
)
关于Mysql 查询不返回订单属性表上的空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51196756/