我在这里发布了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”子句。