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
錯誤是因爲子查詢與外部查詢沒有關聯,但是 - 子查詢根本就沒有必要。 – 2012-03-25 15:16:16