我有以下在 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
我有几个像这样的查询,我想“联合”。如果我“联合”只有 2 个查询它正在工作,但是当我尝试“联合超过 2 个”时,Access 告诉我查询中的列数不相等。
我尝试将这个相同的查询“联合”三次(这样我可以确定三个查询中的列数相同):
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
但它也不起作用。
你知道我做错了什么吗?
提前致谢。