So I have a table that looks something like this, where I have user messages store, along with their status (read ('R') or unread ('U')). They are also stored with a status number, to show their sequence in a thread of messages.
messageid userid sequence status
93 250 1 A
93 250 2 U
93 250 3 U
94 250 1 A
95 250 1 U
I would like to count the unread messages in this table for userid# 250. The resulting rows should be:
messageid userid sequence status
93 250 3 U
95 250 1 U
I have the easy part down, but believe I need to inner join with a SELECT(max). Here's the easy part, which works well:
SELECT messageid FROM message_recips WHERE message_recips.userid=250 AND message_recips.status='N'
Heres what cannot figure out the syntax in adding:
AND message_recips.sequence=(SELECT MAX(message_recips.sequence))
Sincere thanks for any help, it is greatly appreciated! mySQLi or mySQL work fine, as I am in the process of switching over.
sequence=3representing the number of unread messages for user 250? According to your data the number of unread messages is 2: the 93 and 95, because they both have an unread part in their sequence.