我有两张表,一张存储传入消息,另一张存储传出消息。我想要的是能够获得消息的对话视图,以便对来自/发往同一用户 ID 的所有传入和传出消息进行分组,并且对话按最新消息(输入或输出)排序
Outgoing
----------
user_id
time
message
Incoming
----------
user_id
time
message
我想要的是显示结果,例如
-> User A 9:10 pm Nice ...
<- User A 8:45 pm Our special is pepperoni!
-> User A 8:00 pm What's your special dish?
<- User B 9:00 pm We open at 5
-> User B 6:56 pm Hello What time to you open?
<- User C 8:43 pm Thanks!
-> User C 4:00 pm Loved the pizza today!!
知道如何编写查询来执行此操作吗?
编辑
如果用户 B 然后发回短信,结果应该是:
-> User B 9:15 pm Ok great!
<- User B 9:00 pm We open at 5
-> User B 6:56 pm Hello What time to you open?
-> User A 9:10 pm Nice ...
<- User A 8:45 pm Our special is pepperoni!
-> User A 8:00 pm What's your special dish?
<- User C 8:43 pm Thanks!
-> User C 4:00 pm Loved the pizza today!!