Help with SQL Query MySql

0

I need to select All messages sent by user 1 to user 2 and to know of messages sent from user 2 to user 1. I am not able to mount the SQL query for the described situation.

Message table:

IdMsg, IdUserFrom, IdUSerTo, Data, Mensagem

Sql that I use only lists the messages sent from user 1 to user 2. All attempts to know the messages sent from user 2 to user 1 that I try to do does not work Being:

$iduserfrom = 1 e IdUserTo = 2

SQL:

SELECT * FROM mensagem WHERE IdUserFrom = $iduserfrom AND IdUserTo = $iduserto
    
asked by anonymous 14.12.2016 / 23:46

1 answer

2

try this:

SELECT * FROM mensagem WHERE (IdUserFrom = $iduserfrom AND IdUserTo = $iduserto) or (IdUserFrom = $iduserto AND IdUserTo = $iduserfrom)
    
15.12.2016 / 01:00