我试图对对话之类的消息进行分组,user1 是@user(登录用户)用户名,UserFullName 始终是未登录用户(与谁进行对话)消息,日期将是拥有最后一条消息的人
example 1:
FromUser | ToUser | Message | Date
User2 | User1 | hi | 01/01/2013 20:00
User1 | User2 | hi back | 01/01/2013 21:00
userfullname and username will be from touser (non logged)
message and date from fromuser (logged in @user, as last message in group)
example 2:
FromUser | ToUser | Message | Date
User1 | User2 | hi | 01/01/2013 20:00
User2 | User1 | hi back | 01/01/2013 21:00
userfullname and username will be from fromuser (non logged in)
message and date from fromuser (logged in @user as its the last message in group)
如果你们中的任何人使用过他们的消息系统,这将像 facebook 对话一样显示。谢谢大家!:) 只想着 sql 就炸我的脑袋
SELECT
CM.FromUser, CM.ToUser, CM.Message, CM.Date,
U.UserId, U.UserFullName, U.UserName, U.UserPhoto
FROM
ConversationMessages AS CM
INNER JOIN
Users AS U ON U.UserName = CM.FromUser
WHERE
CM.ToUser = @user
ORDER BY
CM.Date DESC