SQL query to get full hierarchy path from different tables

早过忘川 提交于 2019-12-06 04:29:10

From what you have shown, I would assume you have 4 tables with a one to many relation between Project and Phase, Phase and Folder and Folder and Document.

Your SQL Statement then could be as simple as joining them all together

SELECT *
FROM   Projects p
       INNER JOIN Phases ph ON ph.ProjectID = p.ProjectID
       INNER JOIN Folders f ON f.PhaseID = ph.PhaseID
       INNER JOIN Documents d ON d.FolderID = f.FolderID

I really don't see a need yet to make it more difficult than need be by throwing in CTE's

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!