按用户名获取最后一条消息对话


get last messages conversation by username

Plis帮助,获取最后一条消息对话!!

数据库:

id,
user_from
user_to
msg

查询php

select * 
from messages 
where 
      user_from = 'Michael' AND 
      user_to = 'Daiana' OR 
      user_from = 'Daiana' AND 
      user_to = 'Michael' 
LEAST(user_to _id, user_from) 
order by id desc 
limit 1

请帮帮我。例如,他没有在Daiana和Michael两位用户的对话中列出最新消息。

示例结果:

  • 戴安娜:你好,你好吗
  • 迈克尔:很好,你呢
  • 戴安娜:很好:)
select * 
from messages 
where 
  (user_from = 'Michael' AND user_to = 'Daiana') 
  OR 
  (user_from = 'Daiana' AND user_to = 'Michael' )
LEAST(user_to _id, user_from) 
order by id desc 
limit 1