0

我在这里发布了 3 个查询。其实我想加入第一个和第二个查询。因为我想获得sc.message的结果以及我的第二个查询结果集。只需检查我的第三个查询,它给出了上述 #1242 错误?请指导我...

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

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

伙计们,我解决了这个问题-:

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
4

1 回答 1

1

尝试在第三个查询的最后一行(“WHERE”行)之后添加“GROUP BY”子句。

于 2012-03-25T15:14:57.617 回答