【问题标题】:mysql to select messages i have sended or recieved from othersmysql 选择我已经发送或从其他人接收的消息
【发布时间】:2019-02-21 03:28:01
【问题描述】:

我是编码新手,

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

消息:

'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

谁能帮帮我?

【问题讨论】:

    标签: php mysqli pdo sqlite


    【解决方案1】:
    SELECT * FROM messages WHERE to_id = :uid OR from_id = :uid
    

    这里不需要使用 UNION。

    【讨论】:

    • 这可能意味着表中的所有行都由您发送或由您接收。您能否将返回但符合条件的示例数据添加到您的问题中?
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 2021-12-11
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多