Вопрос

I have posted 3 queries here. Actually I want to join 1st & 2nd query. As I want to have result of sc.message along with my 2nd query resultset. Just check my third query which gives above #1242 error? Plz guide me...

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

So plz tell me how to resolve this?

Guys, I resolve the issue-:

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
Это было полезно?

Решение

Try adding a "GROUP BY"-clause after the last row (the "WHERE"-row) in the third query.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top