繁体   English   中英

mysql 查询特定用户的发送和接收消息

[英]mysql query for send and receiver messages for particular user

我想查询以提取特定用户下的发送和接收消息。 假设我试图提出理解问题。

有用户列表,当我点击用户时,所有通信数据都应该在这个特定用户下。

我正在使用的查询

SELECT id,post_id
     , post_auth_user_id
     , ask_user_id
     , response_user_id
     , message
     , updated_at 
  FROM post_queries 
 WHERE (4 IN (ask_user_id,response_user_id) 
       OR 2 IN (ask_user_id)) 
    OR (ask_user_id=4 AND response_user_id=0)

但是这个查询没有给我合适的结果。

我希望所有结果都像这种格式。

id post_id post_auth_user_id ask_user_id response_user_id 消息updated_at


 1        2                  2            3                 0  asking property  2020-10-10 14:09:14   
 3        2                  2            3                 2  yeh response hei  2020-10-10 15:19:14  

如果你想要两个用户之间的消息——比如 2 和 4——你可以使用:

SELECT id, post_id, post_auth_user_id, ask_user_id, response_user_id, message, updated_at
FROM (ask_user_id = 2 AND response_user_id = 4) OR
     (ask_user_id = 4 AND response_user_id = 2) ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM