users tbl:
id
username
first_name
last_name
email_address
messages tbl:
id
date_sent
title
content
status
message_relation tbl:
id
message_id
sender_id
receiver_id
What would be the most efficient way to query a message TO a selected user given these tables? In other words, I want to list all messages that are in userA’s “inbox”
Secondly, how would you recommend handling global messages that need to be sent to everyone from the admin?
I think this is what you’re looking for..
This does what you asked for efficiently. If you also want to select fields on either of the users, you can JOIN Receiver_ID to User_ID to to get that.
Suggested tables setup if you want Global/Admin messages:
Then, to query an Inbox, something like:
That will give you a result you can loop through to get a user’s entire Inbox.