I have a query that should bring the name of the users who received a message sent by a user:
SELECT msg.msg_content
,usr.user_name
FROM message AS msg
INNER JOIN usuarios AS usr
ON msg.user_id_out = usr.user_ssid
WHERE usr.user_email = "***"
In the format above, it does not return any results, however when removing% with%, it displays all messages with the name of the recipient, I am in this doubt where I can not imagine the output, I need to display the messages and the names of those who received, but only from whom sent, from whom I received, I can get the Where
, but not only from whom I sent it.
So much to insist I ended up hitting my head on the problem, just start another where
, I do not know if it is the best way, but it worked, if someone knows a better way, help me there, I accept recommendations, but at first I put another inner join
SELECT msg.msg_content
,usr.user_name
FROM message AS msg
INNER JOIN usuarios AS usr
ON msg.user_id_out = usr.user_ssid
INNER JOIN usuarios AS usr_in
ON usr_in.user_ssid = msg.user_id_in
WHERE usr_in.user_email = "***"
Can anyone validate if this is the best way?