mysql - 如何在 Mysql 中解决此问题(#1242 - 子查询返回超过 1 行)?

标签 mysql sql mysql-error-1242

我在这里发布了 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

最佳答案

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

关于mysql - 如何在 Mysql 中解决此问题(#1242 - 子查询返回超过 1 行)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9861171/

相关文章:

mysql - 如果第二个表满足要求,则从多个表中选择数据

Mysql 查询 - 子查询返回多于 1 行错误

php - 注册页面上的 mysql_real_escape_string

php - 如何从 MySql Query 提供的经纬度获取半径内的所有结果

mysql - VBA代码中的SQL语法

mysql - SQL 连接映射表并返回列而不是行

带 IN 和 if-subquery 的 Mysql 查询不起作用

mysql - 子查询在 mysql 中返回多于 1 行

mysql - 哪个更快 : a lookup on a large denormalized table or a join between three smaller tables?

mysql - 如何通过两个过滤器来加速mysql查询