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用户的对话中列出最新消息。
示例结果:
答案 0 :(得分:0)
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