Sample Header Ad - 728x90

Finding id of last child in table structure

0 votes
1 answer
50 views
I have DB structure like this one: structure . message_id from_user_id to_user_id subject body date_add parent_message_id 1 1 2 message 1 body 1 2024-07-01 null 2 2 1 message 2 body 2 2024-07-01 1 3 1 2 message 3 body 3 2024-07-01 2 4 2 1 message 4 body 4 2024-07-01 null 5 1 2 message 5 body 5 2024-07-01 null 6 1 2 message 6 body 6 2024-07-01 null 7 2 1 message 7 body 7 2024-07-01 6 8 1 2 message 8 body 8 2024-07-01 7 I'm looking for efficient way to find last_message_id in each thread and total message count in each thread. If you have messages connected together with parent_message_id this create message thread (like in Gmail). For example for: message_id last_thread_message_id total_thread_count 1 3 3 2 3 3 3 3 3 4 4 1 5 5 1 6 8 3 7 8 3 8 8 3 thanks for advice R.
Asked by Robert (141 rep)
Jul 1, 2024, 01:59 PM
Last activity: Jul 2, 2024, 12:00 PM