为什么要复制我的行? SQL

时间:2016-11-02 08:36:25

标签: sql-server

我有表Orders_Header,Order_Sequence,Orders_Samples有值。我想从3个表中获取唯一值:

我在Orders_Header中有一行:

enter image description here

我在Orders_Sequence中有两行: enter image description here

我在Orders_Samples中有4行:

enter image description here

我的Sql代码是:

SELECT orders_header.plant, 
       orders_header.shortyear, 
       orders_header.orderno, 
       orders_header.orderdate, 
       orders_header.closingdate, 
       orders_header.requester, 
       orders_header.projectnumber, 
       orders_header.costcenter, 
       orders_header.batchnumber, 
       orders_header.partname, 
       orders_header.partnumber, 
       orders_header.costcategory, 
       orders_header.status, 
       orders_header.overallproductrating, 
       orders_sequence.activitynumber, 
       orders_sequence.dimension, 
       orders_sequence.description, 
       orders_sequence.activityname, 
       orders_sequence.activityresource, 
       orders_sequence.requirementnom, 
       orders_sequence.requirementplus, 
       orders_sequence.requirementminus, 
       orders_sequence.units, 
       orders_samples.samplenumber, 
       orders_samples.samplevalue 
FROM   orders_header 
       INNER JOIN orders_sequence 
               ON orders_header.orderid = orders_sequence.orderid 
       INNER JOIN orders_samples 
               ON orders_samples.orderid = orders_sequence.orderid 
WHERE  ( orders_header.orderno = 79148 ) 
       AND ( orders_header.shortyear = 16 ) 

为什么我得到8行而不是4行,我想要唯一的行。我在Orders_Samples中有4行,我希望最后4行包含所有日期。

我尝试使用不同但不起作用

由于

0 个答案:

没有答案