查询聊天消息SQL语句!
select top 10 f.Name as 'Formusername',t.Name as 'ToUsername',m.id,m.Fromuserid,m.TouserId,m.Message,m.recordTime,m.messageState,m.readflag from Message as m
inner join Users as f on f.Id=m.FromUserId
inner join Users as t on t.Id=m.ToUserId
order by recordtime desc
Message 表
Users 表
inner join 内连接查询,效率高!
发稿地址