displaying CERTAIN information in a sql (below a certain value)
im making this messaging system and im having trouble. Basically, its a thread type system, sort of like facebook style messaging. User 1 sends user 75 a message (message 1 and thread 1) is created, and user 75 replys with a message (message 2 is created in thread 1) and so on and so on. Now im able to display everything perfectly.
Lets say it gets to a point where it user75 submits his 5th rep开发者_如何学Goly on that thread (message 13), and user 1 deletes the message to clean up his inbox (NOW message 5 has the value of "deleted")..... if user 75 replies, then EVERY MESSAGE in that thread will show up again to him. I want it to work in a way, that user 75's reply will seem like a new thread to user 1 (but its not, how can i achive this in sql) here is the sql to display the messages in the thread
mysql> SELECT message_id,thread_id,messages.user_id,to_id,messages.subject,messages.body,from_message_status,to_message_status,message_status,new,messages.date FROM messages
-> INNER JOIN users ON users.id = messages.user_id
-> INNER JOIN messages_thread ON messages_thread.id = messages.thread_id
-> WHERE thread_id = 1
-> GROUP BY messages.message_id ORDER BY message_id ASC ;
+------------+-----------+---------+-------+---------+---------------------------------------------------------------+---------------------+-------------------+----------------+-----+------------+
| message_id | thread_id | user_id | to_id | subject | body | from_message_status | to_message_status | message_status | new | date |
+------------+-----------+---------+-------+---------+---------------------------------------------------------------+---------------------+-------------------+----------------+-----+------------+
| 1 | 1 | 75 | 1 | | Wassup man. | unread | unread | deleted | 0 | 1312493817 |
| 2 | 1 | 1 | 75 | | im chilling , and you? | unread | unread | read | 0 | 1312493867 |
| 3 | 1 | 75 | 1 | | Yea same same just posted man trying to find something to do. | unread | unread | deleted | 0 | 1312493895 |
| 4 | 1 | 75 | 1 | | what you trying to get into today? | unread | unread | deleted | 0 | 1312493904 |
| 5 | 1 | 75 | 1 | | just play some video games or something. you? | unread | unread | deleted | 0 | 1312494046 |
| 6 | 1 | 75 | 1 | | hello? dude? | unread | unread | read | 0 | 1312494108 |
+------------+-----------+---------+-------+---------+---------------------------------------------------------------+---------------------+-------------------+----------------+-----+------------+
Like do you see the last delete in message_status? im trying to display everything below that
SELECT ... FROM messages
INNER JOIN users ON users.id = messages.user_id
INNER JOIN messages_thread ON messages_thread.id = messages.thread_id
WHERE thread_id = 1
AND message_id >
(SELECT max(message_id) FROM messages
WHERE thread_id = 1 and message_status = 'DELETED')
GROUP BY messages.message_id ORDER BY message_id ASC ;
精彩评论