2012-03-25 72 views
0

我已经在这里发布了3个查询。其实我想加入第一个&第二个查询。因为我想要得到结果sc.message以及我的第二个查询结果集。只是检查我的第三个查询,它给出#1242错误以上? PLZ引导我...如何在Mysql中解决此问题(#1242 - 子查询返回多于1行)?

Query1=(SELECT sc.message 
     FROM sales_flat_order sfo, `sales_flat_order_item` `sfoi` 
     LEFT JOIN `shipping_comment` `sc` ON 
    `sfoi`.`shipping_comment_id` = `sc`.`shipping_comment_id` 
     WHERE sfoi.order_id = sfo.entity_id 
     AND sfo.increment_id = 100000429) 



Query2= (SELECT sfoi.name, sfoi.sku, sfoi.qty_ordered, sfoi.price, sfoi.row_total, sfo.base_subtotal, 
    sfo.base_shipping_amount, sfo.base_grand_total 
    FROM sales_flat_order sfo 
    JOIN sales_flat_order_item sfoi 
    ON sfoi.order_id = sfo.entity_id 
    WHERE sfo.increment_id = 100000429) 

Query3 = SELECT sfoi.name, sfoi.sku, sfoi.qty_ordered, sfoi.price, sfoi.row_total, sfo.base_subtotal, 
sfo.base_shipping_amount, sfo.base_grand_total, 
(SELECT sc.message 
FROM sales_flat_order sfo, `sales_flat_order_item` `sfoi` 
LEFT JOIN `shipping_comment` `sc` ON `sfoi`.`shipping_comment_id` = `sc`.`shipping_comment_id` 
WHERE sfoi.order_id = sfo.entity_id 
AND sfo.increment_id = 100000429) 
FROM sales_flat_order sfo 
JOIN sales_flat_order_item sfoi 
ON sfoi.order_id = sfo.entity_id 
WHERE sfo.increment_id = 100000429 

所以PLZ告诉我如何解决这个问题?

伙计们,我化解发出─:

SELECT sfoi.name, sfoi.sku, sfoi.qty_ordered, sfoi.price, 
sfoi.row_total, sfo.base_subtotal, sfo.base_shipping_amount, 
sfo.base_grand_total,sc.message 
FROM sales_flat_order sfo 
JOIN sales_flat_order_item sfoi 
ON sfoi.order_id = sfo.entity_id 
LEFT JOIN `shipping_comment` `sc` 
ON `sfoi`.`shipping_comment_id` = `sc`.`shipping_comment_id` 
WHERE sfo.increment_id = 100000429 
+0

错误是因为子查询与外部查询没有关联,但是 - 子查询根本就没有必要。 – 2012-03-25 15:16:16

回答

1

尝试在第三个查询增加一个 “GROUP BY” -clause最后一行之后(在 “WHERE” - 行)。

相关问题