0

次のクエリは、Acces 2007 で完全に実行されます。

SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id

「UNION」したいこのようなクエリがいくつかあります。2 つのクエリだけを "UNION" すると動作しますが、"2 つ以上の UNION" を実行しようとすると、クエリの列数が等しくないことが Access から通知されます。

この同じクエリを次のように 3 回 "UNION" しようとしました (このようにして、3 つのクエリで列の数が同じであることを確認します)。

SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id
UNION ALL
SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id
UNION ALL
SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id

しかし、それも機能していません。

私が間違っていることについて何か考えがありますか?

前もって感謝します。

4

1 に答える 1

0
SELECT A.Activity,A.id,A.ItemLeft,A.LeftRefLastRev,A.ItemRight,A.RightRefLastRev,A.Valid
FROM           
    (
        SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
        FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id
        UNION ALL
        SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
        FROM ((ProjectReferences AS ProjectReferences_1 INNER JOIN ProjectRTMSystemRequirements ON ProjectReferences_1.Id = ProjectRTMSystemRequirements.reference) INNER JOIN ProjectRTMAcquisitionNeeds ON ProjectRTMSystemRequirements.Id = ProjectRTMAcquisitionNeeds.SystemRequirement.Value) INNER JOIN ProjectReferences ON ProjectRTMAcquisitionNeeds.reference = ProjectReferences.Id
    ) A
        UNION ALL
        SELECT "Concept" AS Activity, ProjectRTMAcquisitionNeeds.Id AS id, ProjectRTMAcquisitionNeeds.AcquisitionNeed AS ItemLeft, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences.title) AS LeftRefLastRev, ProjectRTMSystemRequirements.SystemRequirement AS ItemRight, (SELECT MAX(rev) FROM ProjectReferences AS PR WHERE PR.title = ProjectReferences_1.title) AS RightRefLastRev, IIf([ProjectReferences].[rev]=[LeftRefLastRev] And [ProjectReferences_1].[rev]=[RightRefLastRev],1,0) AS Valid
于 2013-10-03T15:13:50.210 に答える