I have a requirement to find the 'current' equivalent course from a list of courses. The list is in a fairly simple format, from an SQL query, and looks like below:
| Course_Code | Course_Title | Course_Status | Parent_Course |
|---|---|---|---|
| HLT31802 | Title1a | Superseded | HLT31807 |
| HLT31807 | Title1b | Superseded | HLT31812 |
| HLT31812 | Title1c | Superseded | HLT35015 |
| HLT35015 | Title1d | Superseded | HLT35021 |
| HLT35021 | Title1e | Current | None |
| ABC12345 | Title2a | Superseded | ABC67890 |
| ABC67890 | Title2b | Current | None |
I'm sure the solution has something to do with recursion, but can't get my head around it. I am happy to post code Ive tried but I didnt get very far without creating multiple columns (child1, child2, etc) in SQL.
Required output would be something like this:
| Course_Code | Current_Course |
|---|---|
| HLT31802 | HLT35021 |
| HLT31807 | HLT35021 |
| HLT31812 | HLT35021 |
| HLT35015 | HLT35021 |
| HLT35021 | HLT35021 |
| ABC12345 | ABC67890 |
| ABC67890 | ABC67890 |
Any help would be appreciated!