2012-06-14 72 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];