I'm in the middle of a project for my Comp Science project for monday, and i came across a MySQL question regarding a Query.
What I want to achieve, through words is this.
If the column to=jake and column from=connor OR column to=connor and column from=jake get the cID from that specific table.
What I have so far is this
$query="SELECT cID FROM conversation WHERE to='$to' AND to='$from' OR to='$from' AND from='$to'";
What is there that I can do to get this query to work? Thanks in advance!
You just need a couple pairs of ()
to group the two conditional pairs, separated by a logical OR
$query="
SELECT cID
FROM conversation
WHERE
/* to Jake, from Connor */
(`to`='$to' AND `from`='$from')
/* OR to connor, from jake */
OR (`to`='$from' AND `from`='$to')";
Note: FROM
and TO
are both MySQL reserved keyword, and thus require quoting with backticks.
This is untested but I would think you need to put the to='$to' AND to='$from' (which should be from not to i guess??) into brackets??
Just realised someone else put this as i was typing it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With