How to resolve this in Mysql (#1242 - Subquery returns more than 1 row )?

别说谁变了你拦得住时间么 提交于 2019-12-08 13:17:02

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/9861171/how-to-resolve-this-in-mysql-1242-subquery-returns-more-than-1-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!