gpt4 book ai didi

mysql - 获取每个对话的最后一条消息

转载 作者:行者123 更新时间:2023-11-29 11:21:43 25 4
gpt4 key购买 nike

我有一个消息表,其中包含id、sender_id、receiver_id、message 和conversation_id

(我通过conversation_id连接它们,它们通过发送第一条消息来创建,如果有人回复,他首先从消息中搜索conversation_id,他是接收者,而他回复的人是发件人,然后使用相同的conversation_id发送消息)

现在,在消息列表中,我想为每个不同的 conversation_id 输出最后一行,其中 sender_id='$my_id' OR receive_id='$my_id'

我正在使用DISTINCT,但我始终将所有行作为输出:

SELECT DISTINCT conversation_id, sender_id, message 
FROM messages
WHERE receiver_id='$my_id'
ORDER BY id DESC

最佳答案

试试这个

SELECT id,conversation_id, sender_id, receiver_id, message FROM message WHERE receiver_id='$my_id' GROUP BY `conversation_id` ORDER BY id DESC LIMIT 1 

关于mysql - 获取每个对话的最后一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38804292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com