We've a table called message.
CREATE TABLE IF NOT EXISTS `message` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from_user_id` int(11) NOT NULL,
`to_user_id` int(11) NOT NULL,
`content` text NOT NULL,
`club_id` int(11) NOT NULL,
`read_flag` int(11) NOT NULL DEFAULT '0',
`parent_id` int(11) NOT NULL,
`status` tinyint(1) DEFAULT NULL,
`create_user_id` int(11) NOT NULL,
`update_user_id` int(11) NOT NULL,
`create_dt_tm` datetime NOT NULL,
`update_dt_tm` datetime NOT NULL,
`delete_flag` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
Need to display the messages and message reply to the user. Entries in the table will like this,
id | from_user_id | to_user_id | content | parent_id
1 | 2 | 3 | hai | 0
2 | 3 | 2 | hi | 1
3 | 3 | 2 | hwru | 1
4 | 3 | 4 | hwru | 1
5 | 4 | 5 | u added | 1
6 | 4 | 5 | new msg | 0
Here is the flow, lets assume 2=>A, 3 =>B, 4 =>C, 5=> D,
- A send a message to B
- B reply to that message
- B send again one more reply by adding new recipient C
- C reply to that thread again by adding new recipient D
- All users part of this thread, should able to read full message thread.
- A,B,C and D can see the all (1,2,3,4,5) messages if they login except 6th
- 6th message only C and D can see and it is a different thread
Two queries I'm using now,
- One for to list all messages.
- Second is for to see the details for that message(when user click on that will show all thread related to that message).
By using single query I need to show the all threads to the login user. Please help some one to select query for this.