Firstly, I was surprised that Access does not seem to allow mutliple joins without nesting. I've used other SQL engines which allow a discrete set of joins to be specified. Anyway, I think this makes it harder, but it should still be doable.
I have the following tables and relationships that I am wanting to exploit.
AP relates 1-to-many to AI.
AI relates 1-to-many to AU.
AU relates to AY 1-to-<none or one>.
I want to find entries in AI that have multiple distinct AU entries. Specifically I want to show each pair of conflicting AU entries (using the same AI), plus I want to include info for each of the AU entries from the related AY. The AP is needed for the description of that entity, but does not otherwise feature.
Here's the SQL I came up with, which is syntactically correct but "unsupported".
The "AS" clauses rename the files to the letter scheme I used to explain above, but with a "1" or "2" suffix for each side of the pairing.
Can anybody suggest an alternate way of doing this, or if I have something wrong in the statement?
I have the following tables and relationships that I am wanting to exploit.
AP relates 1-to-many to AI.
AI relates 1-to-many to AU.
AU relates to AY 1-to-<none or one>.
I want to find entries in AI that have multiple distinct AU entries. Specifically I want to show each pair of conflicting AU entries (using the same AI), plus I want to include info for each of the AU entries from the related AY. The AP is needed for the description of that entity, but does not otherwise feature.
Here's the SQL I came up with, which is syntactically correct but "unsupported".
Code:
SELECT AP.Application, AI.Server, AI.Instance, AI.Status, AU1.Project, AU1.Role, AY1.Activity, AU2.Project, AU2.Role, AY2.Activity
FROM Application AS AP, [Application Instances] AS AI, [Application Use] AS AU1, Activity AS AY1, [Application Use] AS AU2, Activity as AY2,
AP INNER JOIN
(AI INNER JOIN
((AU1 LEFT JOIN AY1 ON AY1.Project = AU1.Project AND AY1.Role = AU1.Role) INNER JOIN
(AU2 LEFT JOIN AY2 ON AY2.Project = AU2.Project AND AY2.Role = AU2.Role)
ON AU2.ID = AU1.ID)
ON AU1.ID = AI.[Application Instance ID])
ON AP.Application = AI.Application
WHERE AU1.Project <> AU2.Project OR AU1.Role <> AU2.Role;
The "AS" clauses rename the files to the letter scheme I used to explain above, but with a "1" or "2" suffix for each side of the pairing.
Can anybody suggest an alternate way of doing this, or if I have something wrong in the statement?