| postid | ref_postid | title |
| 1 | 0 | Title 1 |
| 2 | 1 | |
| 3 | 1 | |
| 4 | 0 | Title 2 |
| 5 | 4 | |
It´s a table for a discussion forum. When ref_postid = 0, that means it is a main post. When ref_postid is not 0 it is a answer and references to a postid, see table example above. (Only main posts has a title.)
I want to select all rows in the table, but the problem is that I want to display the title for the discussion an answer refers to.
Example: Let´s say I want the row where postid = 2, I also want to get “Title 1” which is the name of the discussion.
I tried doing it with CASE but I just got errors. I´m not very good at this. Is it doable with one query? Or will I have to use two queries?
Thanks for your help!
1 Answer