我有一个表“消息”。
字段是:
- id (primary key, int, auto increment)
- uid (the user who sent the message)
- rid (the user who received the message)
- text (text of the message)
- time (time of message)
- read (read or unread. 0 is unread, 1 is read).
作为一个用户来说,我可以是UID,也可以是RID。因此,如果我想显示我发送/接收消息的用户列表,我该怎么做?另外,每个用户应该只显示一次。请帮忙。谢谢。 :)
最佳答案
一种可能的方法是使用 UNION(而不是 UNION ALL),以便删除重复的行:
SELECT uid FROM messages WHERE rid = 'me'
UNION
SELECT rid FROM messages WHERE uid = 'me'
关于mysql - 列出所有发送或接收消息的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14029044/