简体   繁体   English

选择查询具有意外的多个记录(MS Access)

[英]Select Query has unexpected multiple records (MS Access)

I may just be tired, but I can't seem to figure out what is happening. 我可能只是累了,但我似乎无法弄清楚正在发生什么。 I have two queries. 我有两个查询。 Query 1 has 10 fields. 查询1有10个字段。 Query 2 has 5 fields. 查询2有5个字段。 Fields 1 through 3 are the same in both queries. 两个查询中的字段1到3相同。 I am trying to write a select query and simple add field 5 from Query2 to Query1 so my result should be Query1 with an additional field (Query2.field5). 我试图编写一个选择查询,并将简单的字段5从Query2添加到Query1,所以我的结果应该是带有附加字段(Query2.field5)的Query1。

I join the first 3 fields from both queries and choose select all records in query1 and only those in query2 that match. 我将两个查询的前3个字段都加入了,并选择选择query1中的所有记录,而只选择query2中匹配的记录。 I don't know sql, so I use query designer. 我不知道sql,所以我使用查询设计器。 I expect to get the same number of records that I have from query 1 but instead I have 3 times or more. 我希望获得与查询1相同的记录数,但我有3次或更多次。 Can someone tell me what I am doing wrong. 有人可以告诉我我在做什么错。 I even tried reversing the joins but still seem to get the same extra records. 我什至尝试反转连接,但似乎仍然得到相同的额外记录。

Thanks in advance. 提前致谢。

Here is the query: 这是查询:

The fields that are in common are DivisionName , SupplierID = VendorID and CommodityName . 共同的字段是DivisionNameSupplierID = VendorIDCommodityName

SELECT [Part Revenue Exposed Query P1].DivisionName, 
        [Part Revenue Exposed Query P1].CommodityName, 
        [Part Revenue Exposed Query P1].SupplierName, 
        [Part Revenue Exposed Query P1].PartNumber, 
        [Part Revenue Exposed Query P1].PartDescription, 
        [Part Revenue Exposed Query P1].BUCode, 
        [Part Revenue Exposed Query P1].ProductLine, 
        [Vendor Risk Score Query].VendorScore

FROM [Part Revenue Exposed Query P1] LEFT JOIN [Vendor Risk Score Query] 

ON ([Part Revenue Exposed Query P1].DivisionName = [Vendor Risk Score Query].DivisionName) 
    AND ([Part Revenue Exposed Query P1].SupplierID = [Vendor Risk Score Query].VendorID) 
    AND ([Part Revenue Exposed Query P1].CommodityName = [Vendor Risk Score Query].CommodityName);

Check you join condition. 检查您的加入条件。

   AND ([Part Revenue Exposed Query P1].SupplierID = [Vendor Risk Score Query].VendorID) 

Is supplier to vendor correct? 供应商对供应商是否正确?

You said the first three fields are the same. 您说前三个字段相同。 But it only shows two the same. 但是它只显示两个相同。

This is most probably because there are multiple records in [Vendor Risk Score Query] matching the condition in [Part Revenue Exposed Query P1]. 这很可能是因为[供应商风险评分查询]中有多条记录与[零件收入暴露查询P1]中的条件匹配。 ie if corresponding to one record of [Part Revenue Exposed Query P1] with values: 即,如果对应于[零件收入暴露查询P1]的一条记录,其值如下:

DivisionName ='TestDiv', SupplierID = 1, CommodityName = 'TestCommodity' DivisionName ='TestDiv',SupplierID = 1,CommodityName ='TestCommodity'

there can be multiple records in [Vendor Risk Score Query] with values [供应商风险评分查询]中可能有多个记录,包含值

DivisionName ='TestDiv', SupplierID = 1, CommodityName = 'TestCommodity' DivisionName ='TestDiv',SupplierID = 1,CommodityName ='TestCommodity'

then it will return more records than the number of records in [Part Revenue Exposed Query P1] 那么它将返回的记录数多于[零件收入暴露查询P1]中的记录数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM