doutang7707 2016-11-14 17:01
浏览 30

MySql,如何从不同用户获取最后的消息

My table looks like this

id INT
from9 VARCHAR 12
to9 VARCHAR 12
message TEXT
datetime9 DATETIME

from9 and to9 are users' ids. Obviously if Susan (ID:susan) sends a message to Jack (ID:jack), row in MySql table will look like:

55 (Auto-increment INT)
susan
jack
Hello Jack how are you doing?
2016-11-14 22:22:22

If Jack sends message back, from9 and to9 will be invese. As you can see I am saving one message for both parties (this is fine). I would like to list all "last" messages either send to me OR sent by me and I am having problems building such query. I was thinking to do workaround and have more queries: 1) get msgs sent to me 2) get msgs sent by me 3) put all those msgs in a set and do final query where I read those IDs.

Is it possible to build one query for this?

  • 写回答

1条回答 默认 最新

  • duanguangwang5829 2016-11-14 17:44
    关注

    I Hope you will get answer from this query

    SELECT max(datetime),msg FROM `message` WHERE from9="a" or to9="a" 
    

    Here "datetime" is my date field name in db and am generating query with a message which is sent or receive by the user "a" last time

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度