MySQL query AND OR operator Logic
computer-science, database, mysql
Solution
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.
Problem
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!