桌子:
+----+----------+-----------+---------+
| id | topic_id | from_user | to_user |
+----+----------+-----------+---------+
| 6 | 5 | 4 | 5 |
| 2 | 6 | 5 | 2 |
| 3 | 5 | 2 | 5 |
| 4 | 4 | 5 | 4 |
| 5 | 4 | 5 | 4 |
| 7 | 6 | 5 | 2 |
| 8 | 5 | 2 | 5 |
| 9 | 5 | 4 | 5 |
| 10 | 0 | 2 | 5 |
| 11 | 6 | 5 | 2 |
| 12 | 3 | 5 | 2 |
| 13 | 0 | 5 | 2 |
+----+----------+-----------+---------+
这是消息表(类似于私人消息),from_user 和 to_user 是自我描述的,topic_id 对此并不重要
现在,我需要选择将在当前登录用户的收件箱中显示的消息列表。我将使用会话变量引用此用户$this_user = $_SESSION['id']
我有这个查询:
SELECT *
FROM messages
WHERE from_user = '$this_user' OR
to_user = '$this_user'
但这将需要重复消息,例如 4 - 5、5 - 4、5 - 4、
我尝试使用 DISTINCT 但也不起作用
任何帮助