Hello again
I am having some trouble getting the right data out of my database, maybe any of you can help me get the right data.
My Tables:
tblReport
ReportID (pk)
Date
joinTable
ReportID
YardID
JoinID (pk)
tblMachines
MachineID (pk)
Machinename
tblTools
ToolID (pk)
Toolname
ReportMachines
ReportID (pk)
MachineID (pk)
ReportTools
ReportID (pk)
ToolID (pk)
---- And some more tables but these are the most important ones that I have trouble with.
Basically I want to select the tools and machines belonging to each Report made.
When I use this query:
The result is:
Machinename - Toolname
Machine1 - Tool1
Machine1 - Tool3
Machine2 - Tool1
Machine2 - Tool3
The result I expected would be:
Machinename - Toolname
Machine1 - Tool1
Machine2 - Tool3
So my database structure is bad or my tables are not correctly joined? Any help is very much appreciated because I am kinda lost in this one.
Thanks for reading already!
I am having some trouble getting the right data out of my database, maybe any of you can help me get the right data.
My Tables:
tblReport
ReportID (pk)
Date
joinTable
ReportID
YardID
JoinID (pk)
tblMachines
MachineID (pk)
Machinename
tblTools
ToolID (pk)
Toolname
ReportMachines
ReportID (pk)
MachineID (pk)
ReportTools
ReportID (pk)
ToolID (pk)
---- And some more tables but these are the most important ones that I have trouble with.
Basically I want to select the tools and machines belonging to each Report made.
When I use this query:
Code:
SELECT DISTINCT tblMachines.Machinename, tblTools.Toolname FROM tblTools INNER JOIN ((tblMachines INNER JOIN (joinTabel INNER JOIN ReportMachines ON joinTabel.JoinID = ReportMachines.ReportID) ON tblMachines.MachineID = ReportMachines.MachineID) INNER JOIN ReportTools ON joinTable.JoinID = ReportTools.ReportID) ON tblTools.ToolID = ReportTools.ToolID WHERE (((joinTabel.JoinID)=2));
Machinename - Toolname
Machine1 - Tool1
Machine1 - Tool3
Machine2 - Tool1
Machine2 - Tool3
The result I expected would be:
Machinename - Toolname
Machine1 - Tool1
Machine2 - Tool3
So my database structure is bad or my tables are not correctly joined? Any help is very much appreciated because I am kinda lost in this one.
Thanks for reading already!
Comment