我使用Access数据库创建了这种关系,但是当我创建一个查询来返回值时,我没有获得所有数据。
如何从tube
或tmc
获取ProjectType
和ProjectId
表中的所有数据?
所以我应该得到类似这样的查询,但访问生成的查询不起作用
SELECT Project.ProjectName,
ProjectSubTypesId.ProjectSubTypesId,
Tube.TubeName, Tube.Duration,
Tmc.TmcName
FROM Tmc
INNER JOIN
(Tube INNER JOIN
(Project INNER JOIN ProjectSubTypesId ON Project.ProjectId = ProjectSubTypesId.ProjectId)
ON Tube.TubeId = ProjectSubTypesId.TubeId) ON Tmc.TmcId = ProjectSubTypesId.TmcId;
答案 0 :(得分:1)
试试这个:
SELECT Project.ProjectName,
ProjectSubTypesId.ProjectSubTypesId
FROM (
(ProjectSubTypes
INNER JOIN Project USING (ProjectId)
)
INNER JOIN Tube USING(TubeId)
)
INNER JOIN Tmc USING(TmcId)
GROUP BY ProjectSubTypes.ProjectId, ProjectSubTypes.TubeId, ProjectSubTypes.TmcId
ORDER BY ProjectSubTypes.ProjectId;
答案 1 :(得分:0)
像这样的工作吗?
SELECT Project.ProjectName,
ProjectSubTypesId.ProjectSubTypesId,
Tube.TubeName, Tube.Duration,
Tmc.TmcName
FROM ((ProjectSubTypes
INNER JOIN Project ON Project.ProjectId = ProjectSubTypes.ProjectId)
INNER JOIN Tube ON Tube.TubeId = ProjectSubTypes.TubeId)
INNER JOIN Tmc ON Tmc.TmcId = ProjectSubTypes.TmcId
ORDER BY ProjectSubTypes.ProjectId;
这应该为您提供所有子类型的列表及其相应的Tube,Tmc和Project数据。
如果可能有多个ProjectSubTypes
行具有相同的TubeId
和TmcId
,请考虑在ORDER BY
行之前添加此行:
GROUP BY ProjectSubTypes.ProjectId, ProjectSubTypes.TubeId, ProjectSubTypes.TmcId