Bob Cohen wrote:
Here's my question. I wrote this query:

Select * FROM name WHERE last LIKE "d" AND choice1="2" OR choice2="2" OR
choice3="2";

To predict the outcome of this query requires knowledge of the precedence of AND vs. OR in mysql. I can't find it documented anywhere, but I think AND has higher precedence than OR. Hence, your WHERE clause evaluates as


WHERE (last LIKE "d" AND choice1="2") OR choice2="2" OR choice3="2"

which is not what you want.

My advice is to never rely on precedence. Instead, I suggest you *always* use parentheses to make it clear what you want. From your description, I think you need:

WHERE last LIKE "d" AND (choice1="2" OR choice2="2" OR choice3="2")

Michael


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to