Help with Mysql SQL Query

Asked

Viewed 38 times

0

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

Message table:

IdMsg, IdUserFrom, IdUSerTo, Data, Mensagem

Sql that I use only lists the Mensagen 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
  • the code seems correct, just exchange 1 for 2 in the second query. you want to make two same queries or list all in one query only?

  • @Italorodrigo, this is the question, I want to do everything in the same consultation, in two I get in a no.

1 answer

2


try like this:

SELECT * FROM mensagem WHERE (IdUserFrom = $iduserfrom AND IdUserTo = $iduserto) or (IdUserFrom = $iduserto AND IdUserTo = $iduserfrom)

Browser other questions tagged

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