I have two tables as follows:-
Users (Table1)
id name email passs
1 u1 uemail1 pass1
2 u2 uemail2 pass2
3 u3 uemail3 pass3
4 u4 uemail4 pass4
Messages (Table2)
mess_id sender receiver message_text send_time
1 1 2 text1 2019-03-25 09:39:05
2 1 2 text2 2019-03-30 15:10:54
3 1 3 text3 2019-03-30 15:11:59
4 1 4 text4 2019-03-30 15:12:48
5 1 4 text5 2019-03-30 15:13:53
6 4 1 text6 2019-04-09 09:26:53
The logged in user is u1 and i want to get the latest conversation which is the 6th one okay.
Now what i want is to find the latest conversation of u1 and with whom and then find the details from users table of other user with whom u1 had the latest conversation
I hope you got my question and it's clear to everyone.
How can i do all this is 1 query
The result will be the other user's detail like this in the above case the user will be u4
id name email passs
4 u4 uemail4 pass4
So far i have tried this but not getting the result what i wanted
select name from users where id=(select receiver_id,sender_id from messages where receiver_id or sender_id=1 order by send_time desc limit 1)