需要 mysql 选择数据的解决方案,直到


Need a solution for mysql select data where until

我有两个人,用户 222 和用户 5555 之间的消息对话,它显示如下:

Conversation-ID 1, Message-ID 5, User-ID 222: "Oh, and I'm happy about that!"
Conversation-ID 1, Message-ID 4, User-ID 222: "And bought me a new car."
Conversation-ID 1, Message-ID 3, User-ID 222: "I just won some money!"
Conversation-ID 1, Message-ID 2, User-ID 5555: "Fine, how are you?"
Conversation-ID 1, Message-ID 1, User-ID 222: "Hi there, how are you?"

现在我正在寻找 PHP/MySQL 中的解决方案,以仅显示来自用户 ID 222 的消息,直到来自用户 ID 5555 的消息。

结果应该是:

Conversation-ID 1, Message-ID 5, User-ID 222: "Oh, and I'm happy about that!"
Conversation-ID 1, Message-ID 4, User-ID 222: "And bought me a new car."
Conversation-ID 1, Message-ID 3, User-ID 222: "I just won some money!"

其实我有

"SELECT * FROM table_conversations WHERE conversation_id='1' and user_id !='5555' ORDER BY message_id DESC"

但当然,这将向我显示来自用户 ID 222 的所有消息。我想要的只是来自用户 ID 222 的最后一条未回复消息

PHP和MySQL中是否有任何命令或解决方案可以得到这个结果,也适用于所有其他对话?

假设消息 ID 指定消息的顺序:

select *
from table_conversation c
where user_id = 222 and
      message_id > (select max(message_id) from table_conversation c2 where user_d = 555);