gpt4 book ai didi

mysql - 获取最后一次对话

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

我需要你的帮助!

问题:我有一个用户之间的消息系统,我需要获取所有对话中的最后一个对话。这意味着,我必须获取最后写入的消息以及 user1 和 user2 之间可能更早的消息的对话。

我的“消息”表结构是这样的:

'id' | 'uidfrom' | 'uidto' | 'content' | 'cdate'

enter image description here

“uidfrom”是撰写消息的用户,“uidto”是接收消息的用户。

你们有想法或者有可能捕捉到最后的对话吗?因此,在本例中,最后写入的消息是 'id' = 5,现在我需要获取 'uidfrom' = 1 AND 'uidto' = 2 + 'uidfrom' = 2 AND 'uidto' = 1 之间的整个对话。

编辑:查询应该是动态的。所以它应该返回最新的消息和对话。例如。当id = 3的消息在2016-07-19-17:13:50写入时,它应该只返回这条消息,因为这种类型只有一条的谈话。还有更多想法吗?

最佳答案

Select *
from message
where
uidfrom IN (select uidfrom,uidto from message order by id desc limit 0,1) AND
uidto IN (select uidfrom,uidto from message order by id desc limit 0,1)

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

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