I am making a message system, much like on facebook. When a user send a new message to a person from their profile, instead of from within messages, i want to check the database if they already have a conversation together.
My tables look like:
messages =>
m_id (message id)
t_id (thread id)
author_id
text
thread_recipients =>
t_id (thread id)
user_id (id of the user belonging to the thread/conversation)
is_read
So basically i have a row for each user belonging to a conversation, and every message has a thread that it belongs to.
So lets say i have user_id 14 and the user im writing to has 16. Then i would need to find out if these rows existed:
t_id user_id is_read
x 16 1
x 14 1
The thread id's would have to match, and there should not be any other users in that thread.
Can this be done in one query?