簡體   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