The database has a pvt_messages table of this type,

SELECT * FROM pvt_messages WHERE id_user_from=2 AND user_from='qwerty' 

Why the query does not return any results?

pvt_messages table

 id_user_from name_user_from user_from 1 name2 qwerty 2 name3 qwerty1 2 name3 qwerty1 2 name3 qwerty1 2 name3 qwerty1 21 name qwerty2 21 name qwerty2 21 name qwerty2 

After all, logically, the result of the query should display

 id_user_from name_user_from user_from 1 name2 qwerty 2 name3 qwerty1 2 name3 qwerty1 2 name3 qwerty1 2 name3 qwerty1 
  • 2
    Because the condition id_user_from = 2 AND user_from = 'qwerty' is not satisfied by any entry in the table. - Opalosolo
  • and how to make what would satisfy? - LLIAKAJI
  • decided everything instead of AND you need OR to set - LLIAKAJI
  • @LLIAKAJI, why do you duplicate information in the table? After all, qwerty1 will always have id = 2, isn't it? - etki
  • @Fike, yes qwerty1 id = 2, I do not duplicate this incomplete table, then just messages from users - LLIAKAJI

1 answer 1

Reply from comments

The condition id_user_from=2 AND user_from='qwerty' will not satisfy any entry in the table. To get the result you need, instead of AND logic ( AND ), you should use OR logic ( OR )

 SELECT * FROM pvt_messages WHERE id_user_from=2 OR user_from='qwerty'