0

我有一个表“消息”。

字段是:

- 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。因此,如果我想显示我发送/接收消息的用户列表,我该怎么做?另外,每个用户应该只显示一次。请帮忙。谢谢。:)

4

2 回答 2

2

一种可能的方法是使用 UNION(不是 UNION ALL),以便删除重复的行:

SELECT uid FROM messages WHERE rid = 'me'
UNION
SELECT rid FROM messages WHERE uid = 'me'
于 2012-12-25T08:40:36.520 回答
0

我假设,你的桌子设计看起来像这样,

ID | UID | RID |TEXT |TIME | READ

所以,我相信,根据你的桌子设计,你可以使用这个

SELECT * FROM messages WHERE rid = 'me' OR uid='me'
于 2012-12-25T08:45:57.697 回答