Mysql 列出发送或接收消息的所有用户

Mysql 列出发送或接收消息的所有用户,mysql,Mysql,我有一张“信息”表 字段包括: - 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). 作为一个用户,我可以

我有一张“信息”表

字段包括:

- 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'

我猜你的桌子设计是这样的

ID | UID | RID |TEXT |TIME | READ
所以,我相信,根据你的桌子设计,你可以使用这个

SELECT * FROM messages WHERE rid = 'me' OR uid='me'