我想做一个类似facebook收件箱的chatbox。
select * from chat where id in(select max(id) from chat where `to`='$user' or `from`='$user' group by `from`)order by id desc"问题是:
约翰给玛丽送信玛丽给约翰送信
它将显示2个结果。我只想将john和marie之间的对话分组在一个select中(就像facebook一样)。我怎样才能在同一时间内从em到分组?
CREATE TABLE IF NOT EXISTS `chat` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`from` varchar(255) NOT NULL DEFAULT '',
`to` varchar(255) NOT NULL DEFAULT '',
`message` text NOT NULL,
`sent` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`recd` int(11) UNSIGNED NOT NULL DEFAULT '0',
);发布于 2015-04-07 12:56:58
希望这就是您要查找的查询
select group_concat(message) from( select '$user‘btw,message from chat where from in('$user1','$user2') or to (’$USER1‘,'$user2') order by sent)按btw分组;
http://sqlfiddle.com/#!9/36177/3
发布于 2015-04-07 14:31:51
This Article可能会改进你的想法,让你建立一个像facebook一样的标准聊天引擎。首先,您必须确认您具有良好设计的模式

https://stackoverflow.com/questions/29480941
复制相似问题