2012-06-14 42 views
1

我在为以下内容创建报表时出现问题,正如您可以通过包含的csv查看的那样,查询正在生成重复项。我已经尝试了许多可以找到的SQL语句的变体,但没有任何运气。MS Access重复记录从相关表查询

主表:tblServers

Server ID,Server name,Hostname,Operating System,Admin Password,Attachments 
1,"ESX","ESX",1,"**************","CS6.txt;WUG.docx" 
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;Updates-WSUS.pdf" 
3,"Deploy","deploy",3,"**************","WUG.docx" 
5,"Newtest","newtest",2,"************", 

辅助表:tblSettings

ID,Server ID,Role,Feature,Application,Setting,sValue 
1,1,1,,,1,"C:\inetpub" 
2,1,1,,,6,"test.com" 
3,1,1,,,4,"testuser" 
4,1,1,,,5,"testpassword" 
5,2,,7,,4,"root" 
6,2,,7,,5,"pword" 
7,2,,5,,6,"techtools.hopto.org" 

第三表:tblIP

ID,Sebnet,Last Octect,Description 
1,"192.168.0",120,"DRAC" 
1,"192.168.0",250,"Giga1" 
2,"192.168.31",9,"VMWARE" 
1,"192.168.31",250,"Giga2" 

查询 - 结果

"Server ID","Server name","Hostname","Operating System","Admin Password","Attachments","Role","Feature","Application","Setting","sValue","IP","Description" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.0.250","Giga1" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.0.250","Giga1" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.0.250","Giga1" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.0.250","Giga1" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.0.120","DRAC" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.0.120","DRAC" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.0.120","DRAC" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.0.120","DRAC" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,1,"C:\inetpub","192.168.31.250","Giga2" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,6,"test.com","192.168.31.250","Giga2" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,4,"testuser","192.168.31.250","Giga2" 
1,"ESX","ESX",1,"**************","CS6 License.txt;WUG.docx",1,,,5,"testpassword","192.168.31.250","Giga2" 
2,"Media","media",2,"**************","**;**",,7,,4,"root","192.168.31.9","VMWARE" 
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;**",,7,,5,"pword","192.168.31.9","VMWARE" 
2,"Media","media",2,"**************","Access-Compare-CSV-Tables-Relationship.pl;**",,5,,6,"**","192.168.31.9","VMWARE" 

任何帮助,将不胜感激

编辑:

SQL查询

SELECT 
    tblServers.[Server ID], 
    tblServers.[Server name], 
    tblServers.Hostname, 
    tblServers.[Operating System], 
    tblServers.[Admin Password], 
    tblServers.Attachments, 
    tblSettings.Role, 
    tblSettings.Feature, 
    tblSettings.Application, 
    tblSettings.Setting, 
    tblSettings.sValue, 
    [tblIP]![Subnet] & "." & [tblIP]![Last Octect] AS IP, 
    tblIP.Description 
FROM (tblServers 
    LEFT JOIN tblSettings ON tblServers.[Server ID] = tblSettings.[Server ID]) 
    INNER JOIN tblIP ON tblServers.[Server ID] = tblIP.[Server ID] 
; 

回答

0

这是Select Distinct是usefu湖

您可以简单地将不同关键字添加到您的查询中,如下所示,以获取重复值。

SELECT Distinct tblServers.[Server ID], tblServers.[Server name], tblServers.Hostname, 
    tblServers.[Operating System], tblServers.[Admin Password], tblServers.Attachments, 
    tblSettings.Role, tblSettings.Feature, tblSettings.Application, tblSettings.Setting, 
    tblSettings.sValue, [tblIP]![Subnet] & "." & [tblIP]![Last Octect] AS IP, 
    tblIP.Description 
FROM (tblServers 
    LEFT JOIN tblSettings ON tblServers.[Server ID] = tblSettings.[Server ID]) 
    INNER JOIN tblIP ON tblServers.[Server ID] = tblIP.[Server ID];