I am making a messaging module.
I need to find the all parents with their last child message.
Like:
+--------------------+----------------------+---------+
| pkUserDiscussionID | fkDiscussionParentID | message |
+--------------------+----------------------+---------+
| 1 | 0 | a |
| 2 | 1 | b |
| 3 | 1 | c |
| 4 | 0 | a |
+--------------------+----------------------+---------+
I need to find the last child of parent node (fkDiscussionParentID=0) with last child (pkUserDiscussionID=1 last child pkUserDiscussionID=3) with message.
Below I found a link close to my answer but not completely:
COUNT of rows with parent id equal to the row we have with a parent id of 0 in one query