I’m making private messages in my website. Everything is okay but I can’t get the list of all the messages that the user sent or received. I have 2 tables. users(id,username,etc..)
and messages (id,user1,user2,message,date)
I’ve tried following to get all list messages for one user
(SELECT DISTINCT * from users WHERE user1 = $userid OR user2 = $userid ORDER BY date ASC)
but I can’t get the messages and I see duplicate values like
User1 User2
2 1
1 2
I want to get just one value for one relation
I'm not sure I understand your question fully, but from my interpretation I think this may help remove duplicate rows for each relationship:
SELECT DISTINCT * FROM messages GROUP BY user1,user2
It’s not working it returns
User1 User2
2 1
1 2
I don’t want to duplicate value