Soumya Santhosh
Soumya Santhosh

Reputation: 13

mysql to select messages i have sended or recieved from others

I am new to coding,

I want to select messages that I sent or received from others. This is my table:

Messages:

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

What W want is like the Facebook inbox .... list messages send by me or received by me.

I tried this code , but it's showing all data's:

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

Can anyone help me?

Upvotes: 0

Views: 73

Answers (1)

maio290
maio290

Reputation: 6732

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

no need to use UNION here.

Upvotes: 1

Related Questions