recursive self query
问题 I have the following table: myTable: +----+----------+ | id | parentID | +----+----------+ | 1 | null | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 4 | ----------------- i would like to get all rows tracing back until there's no parentID anymore. So ".... WHERE id=5" would give me: 5, 4, 2, 1 回答1: You are organizing your hierarchical data using the adjacency list model. The fact that such recursive operations are difficult is in fact one major drawback of this model. Some DBMSes, such as SQL Server