使用左外连接时,第二表中的数据重复

时间:2016-07-04 02:45:55

标签: mysql sql

大家早上好。我正在创建一个MySQL命令 做这个输出。

enter image description here

但是当我尝试时,输出就是这个。

enter image description here

这是我的代码。

select purchorder.PONo,purchorder.ItemCode,purchorder.Description,
purchorder.OrderQty,
receiving.ItemCode,receiving.Description,Receiving.ReceivedQty from purchorder
LEFT OUTER JOIN Receiving on receiving.RIno = purchorder.RINumber where 
purchorder.PONo = 'P0239ROI'
Group BY purchorder.ItemCode;

表PurchOrder

enter image description here

表格Rceiving

enter image description here

如何实现上述输出? (使用黄色标题)

以下是最新可能的答案

enter image description here TYSM

1 个答案:

答案 0 :(得分:0)

您可以实现这一点,只需删除group by子句并在receiving.RIno子句中添加SELECT

SELECT DISTINCT
    purchorder.PONo,
    purchorder.ItemCode,
    purchorder.Description,
    purchorder.OrderQty,
    receiving.RIno,
    receiving.ItemCode,
    receiving.Description,
    Receiving.ReceivedQty
FROM purchorder
LEFT JOIN Receiving ON receiving.RIno = purchorder.RINumber
AND Receiving.ItemCode = purchorder.ItemCode
WHERE purchorder.PONo = 'P0239ROI'