Query with sql does not return when using WHERE

Asked

Viewed 71 times

0

I have a query that should bring the name of 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 above format, it does not return any results, but when removing the Where, it displays all messages with the name of who received, I am with this doubt where I am unable to imagine the output, I need to display the messages and the names of who received, but only from who sent, from whom I received the where, but not only from the one who sent it


From so much insisting I ended up hitting my head on the problem, just start one more inner join, I don’t know if this 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 one 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 someone validate if this is the best way?

  • 1

    You can’t help much, because you know which tables you have :/ ..

  • could help me how to return then the names of users out of a table related to another with users in the same table, exemplifying, table user, table message, user sends message (out) user receives message (in) table message receives id out and in, select name out and in

  • exchange " for ', your query is correct, probably Where is filtering the data and not found results, check whitespace. there is email equal to '***' ?

  • in fact, neither " or ' returned any value before entering the second Inner Join, I hid the email from the above representation, with the second Inner Join it works perfectly, but I do not know if it is advisable, by the way, as I use in php the PDO :email so it makes no difference the " or ' as not used

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.