mysql来选择我已经从其他人发送或接收的消息

时间:2018-09-17 08:38:49

标签: php mysqli pdo sqlite

我是编码新手,

我想选择我从其他人发送或接收的消息。 这是我的桌子:

消息:

'id' // primary id, auto increment
'from_id' // user id who sent message
'to_id' // friend id who received message
'to_name' //name  who received message
'to_email' // email who received message
'message' // message
'chat_time' //

W想要的就像Facebook的收件箱....列出我发送或接收的消息。

我尝试了这段代码,但是它显示了所有数据:

SELECT * FROM messages where to_id=:uid 
   UNION ALL
       SELECT  * FROM messages WHERE from_id = :uid

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

SELECT * FROM messages WHERE to_id = :uid OR from_id = :uid

无需在此处使用UNION。