query = "SELECT `receiver` as chat_users FROM inbox WHERE receiver='$my_id' or sender='$my_id' UNION SELECT `sender` FROM inbox'";
$run = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($run)){
$chat_user_id= $row['users'];
query2 = "SELECT * FROM inbox WHERE receiver=$my_id AND sender=$chat_user_id UNION SELECT * FROM inbox WHERE receiver=$chat_user_id AND sender=$my_id LIMIT 1";`enter code here`
}
说明: -这与聊天系统有关 -第一个查询返回聊天用户的唯一列表,即与我聊天的用户。 -在第二次查询中,我得到了我和另一个聊天用户之间的最后一条消息。
查询工作正常,但我想以更好的方式做到这一点,是否可以将这两个sql查询合并为1个?