我想要实现的是这样的:
SELECT *
FROM conv
WHERE (WHERE from_user = 3 OR to_user = 3)
AND (WHERE conv = 6_3 OR conv = 3_6)
因此有时conv
字段的格式为[from_to]
,其他时间为[to_from]
,具体取决于谁开始了对话。我想列出由我或其他用户对我开始的对话发送给我的消息。
答案 0 :(得分:3)
应该这么简单:
SELECT *
FROM conv
WHERE (from_user = 3 OR to_user = 3)
如果你想要“功夫”版本,试试这个:
SELECT *
FROM conv
WHERE 3 IN (from_user, to_user)
答案 1 :(得分:2)
一次编写WHERE
个关键字。
SELECT * FROM conv WHERE (from_user = 3 OR to_user = 3) AND (conv = 6_3 OR conv = 3_6
答案 2 :(得分:1)
只需删除多余的WHERE
s:
SELECT *
FROM conv
WHERE (from_user = 3 OR to_user = 3)
AND (conv = "6_3" OR conv = "3_6")
我还将conv
值包含在"
中,因为INT
不能包含_
,因此必须将其存储为VARCHAR
(因此需要"
s。。